-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: switch to event listener internally (#1108)
- Loading branch information
1 parent
ca9585b
commit 9aafd39
Showing
4 changed files
with
72 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Classes/EventListener/AfterQueueItemAddedEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\EventListener; | ||
|
||
use AOE\Crawler\Domain\Repository\QueueRepository; | ||
use AOE\Crawler\Event\AfterQueueItemAddedEvent; | ||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class AfterQueueItemAddedEventListener | ||
{ | ||
public function __invoke(AfterQueueItemAddedEvent $event): void | ||
{ | ||
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(QueueRepository::TABLE_NAME) | ||
->update(QueueRepository::TABLE_NAME, $event->getFieldArray(), [ | ||
'qid' => (int) $event->getQueueId(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Tests/Functional/EventListener/AfterQueueItemAddedEventListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\Tests\Functional\EventListener; | ||
|
||
use AOE\Crawler\Domain\Repository\QueueRepository; | ||
use AOE\Crawler\Event\AfterQueueItemAddedEvent; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
class AfterQueueItemAddedEventListenerTest extends FunctionalTestCase | ||
{ | ||
/** | ||
* @var non-empty-string[] | ||
*/ | ||
protected array $testExtensionsToLoad = ['typo3conf/ext/crawler']; | ||
|
||
private EventDispatcher $eventDispatcher; | ||
private QueueRepository $queueRepository; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->eventDispatcher = GeneralUtility::makeInstance(EventDispatcher::class); | ||
$this->queueRepository = GeneralUtility::makeInstance(QueueRepository::class); | ||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/tx_crawler_queue.csv'); | ||
} | ||
|
||
#[Test] | ||
public function listenerIsInvoked(): void | ||
{ | ||
$event = new AfterQueueItemAddedEvent(1001, [ | ||
'parameters' => 'test params', | ||
]); | ||
$this->eventDispatcher->dispatch($event); | ||
|
||
$queueItem = $this->queueRepository->getQueueEntriesByQid(1001, true); | ||
self::assertEquals('test params', $queueItem['parameters']); | ||
} | ||
} |