Skip to content

Commit

Permalink
Ensure the eventhandler runs after catalog update
Browse files Browse the repository at this point in the history
  • Loading branch information
usox committed Jan 22, 2022
1 parent 8579429 commit 0d00f9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Component/Cli/CatalogUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ahc\Cli\Input\Command;
use Psr\Container\ContainerInterface;
use Uxmp\Core\Component\Catalog\Manage\CatalogUpdaterInterface;
use Uxmp\Core\Component\Event\EventHandlerInterface;

final class CatalogUpdateCommand extends Command
{
Expand All @@ -30,6 +31,11 @@ public function __construct(

public function execute(?int $catalogId): void
{
$this->dic->get(CatalogUpdaterInterface::class)->update($this->app()?->io(), (int) $catalogId);
$this->dic->get(CatalogUpdaterInterface::class)->update(
$this->app()?->io(),
(int) $catalogId
);

$this->dic->get(EventHandlerInterface::class)->run();
}
}
11 changes: 10 additions & 1 deletion tests/Component/Cli/CatalogUpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\MockInterface;
use Psr\Container\ContainerInterface;
use Uxmp\Core\Component\Catalog\Manage\CatalogAdderInterface;
use Uxmp\Core\Component\Catalog\Manage\CatalogUpdaterInterface;
use Uxmp\Core\Component\Event\EventHandlerInterface;

class CatalogUpdateCommandTest extends MockeryTestCase
{
Expand All @@ -36,13 +36,18 @@ public function testExecuteExecutes(): void
{
$catalogUpdater = Mockery::mock(CatalogUpdaterInterface::class);
$interactor = Mockery::mock(Interactor::class);
$eventHandler = Mockery::mock(EventHandlerInterface::class);

$catalogId = 666;

$this->dic->shouldReceive('get')
->with(CatalogUpdaterInterface::class)
->once()
->andReturn($catalogUpdater);
$this->dic->shouldReceive('get')
->with(EventHandlerInterface::class)
->once()
->andReturn($eventHandler);

$catalogUpdater->shouldReceive('update')
->with($interactor, $catalogId)
Expand All @@ -53,6 +58,10 @@ public function testExecuteExecutes(): void
->once()
->andReturn($interactor);

$eventHandler->shouldReceive('run')
->withNoArgs()
->once();

$this->subject->execute($catalogId);
}
}

0 comments on commit 0d00f9e

Please sign in to comment.