for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace EventSauce\EventSourcing\TestUtilities\TestingAggregates;
use EventSauce\EventSourcing\AggregateRoot;
use EventSauce\EventSourcing\AggregateRootRepository;
/**
* @testAsset
*/
class DummyCommandHandler
{
* @phpstan-var AggregateRootRepository<DummyAggregate>
private AggregateRootRepository $repository;
* @phpstan-param AggregateRootRepository<DummyAggregate> $repository
public function __construct(AggregateRootRepository $repository)
$this->repository = $repository;
}
* @throws DummyException
public function handle(DummyCommand $command): void
try {
if ($command instanceof InitiatorCommand) {
$aggregate = DummyAggregate::create($command->aggregateRootId());
return;
/** @var DummyAggregate $aggregate */
$aggregate = $this->repository->retrieve($command->aggregateRootId());
if ($command instanceof PerformDummyTask) {
$aggregate->performDummyTask();
} elseif ($command instanceof IgnoredCommand) {
$aggregate->dontDoAnything();
} elseif ($command instanceof ExceptionInducingCommand) {
$aggregate->throwAnException();
} elseif ($command instanceof DummyIncrementCommand) {
$aggregate->increment();
} finally {
if (isset($aggregate)) {
$this->repository->persist($aggregate);