Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use EventSauce\EventSourcing\TestUtilities\AggregateRootTestCase;

/**
* @method DummyAggregateRootId aggregateRootId()
* @extends AggregateRootTestCase<DummyAggregateRootId, AggregateRootWithDelegatedBehavior>
*/
class AggregateRootWithDelegatedBehaviorTest extends AggregateRootTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Closure;
use EventSauce\EventSourcing\TestUtilities\AggregateRootTestCase;

/**
* @extends AggregateRootTestCase<ShoppingCartId, ShoppingCart>
*/
class ShoppingCartTestCase extends AggregateRootTestCase
{
protected function newAggregateRootId(): ShoppingCartId
Expand All @@ -21,7 +24,6 @@ protected function aggregateRootClassName(): string

public function handle(Closure $closure): void
{
/** @var ShoppingCart $aggregate */
$aggregate = $this->repository->retrieve($this->aggregateRootId);
$closure($aggregate);
$this->repository->persist($aggregate);
Expand Down
3 changes: 3 additions & 0 deletions src/Snapshotting/Tests/AggregateSnapshottingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use EventSauce\EventSourcing\Snapshotting\Snapshot;
use EventSauce\EventSourcing\TestUtilities\AggregateRootTestCase;

/**
* @extends AggregateRootTestCase<LightSwitchId, LightSwitch>
*/
class AggregateSnapshottingTest extends AggregateRootTestCase
{
protected InMemorySnapshotRepository $snapshotRepository;
Expand Down
3 changes: 1 addition & 2 deletions src/Snapshotting/Tests/LightSwitchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use EventSauce\EventSourcing\TestUtilities\AggregateRootTestCase;

/**
* @method LightSwitchId aggregateRootId()
* @extends AggregateRootTestCase<LightSwitchId, LightSwitch>
*/
class LightSwitchTest extends AggregateRootTestCase
{
Expand Down Expand Up @@ -68,7 +68,6 @@ protected function handle(object $command): void
return;
}

/** @var LightSwitch $lightSwitch */
$lightSwitch = $this->retrieveAggregateRoot($command->id());

if ($command instanceof TurnLightOn) {
Expand Down
21 changes: 18 additions & 3 deletions src/TestUtilities/AggregateRootTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
use function sprintf;

/**
* @template AggregateRootIdType of AggregateRootId
* @template AggregateRootType of AggregateRoot<AggregateRootIdType>
*
* @method handle(...$arguments)
*/
abstract class AggregateRootTestCase extends TestCase
Expand All @@ -51,7 +54,7 @@ abstract class AggregateRootTestCase extends TestCase
protected $messageRepository;

/**
* @phpstan-var AggregateRootRepository<AggregateRoot>
* @phpstan-var AggregateRootRepository<AggregateRootType>
*/
protected AggregateRootRepository $repository;

Expand Down Expand Up @@ -81,7 +84,7 @@ abstract class AggregateRootTestCase extends TestCase
private $assertedScenario = false;

/**
* @var AggregateRootId
* @var AggregateRootIdType
*/
protected $aggregateRootId;

Expand Down Expand Up @@ -109,11 +112,17 @@ protected function setUpEventSauce(): void
$this->caughtException = null;
}

/**
* @return AggregateRootType
*/
protected function retrieveAggregateRoot(AggregateRootId $id): object
{
return $this->repository->retrieve($id);
}

/**
* @param AggregateRootType $aggregateRoot
*/
protected function persistAggregateRoot(AggregateRoot $aggregateRoot): void
{
$this->repository->persist($aggregateRoot);
Expand Down Expand Up @@ -142,15 +151,21 @@ protected function assertScenario(): void
}
}

/**
* @return AggregateRootIdType
*/
protected function aggregateRootId(): AggregateRootId
{
return $this->aggregateRootId;
}

/**
* @return AggregateRootIdType
*/
abstract protected function newAggregateRootId(): AggregateRootId;

/**
* @phpstan-return class-string<AggregateRoot>
* @phpstan-return class-string<AggregateRootType>
*/
abstract protected function aggregateRootClassName(): string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use PHPUnit\Framework\ExpectationFailedException;

/**
* @method DummyAggregateRootId aggregateRootId()
* @extends AggregateRootTestCase<DummyAggregateRootId, DummyAggregate>
*/
class ExampleAggregateRootTest extends AggregateRootTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use LogicException;

/**
* @method DummyAggregateRootId aggregateRootId()
* @extends AggregateRootTestCase<DummyAggregateRootId, DummyAggregate>
*/
class TestCaseMustHaveHandleMethodsTest extends AggregateRootTestCase
{
Expand Down
4 changes: 3 additions & 1 deletion tests/ShoppingCartTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use EventSauce\EventSourcing\LibraryConsumptionTests\ShoppingCartExample\ShoppingCartId;
use EventSauce\EventSourcing\TestUtilities\AggregateRootTestCase;

/**
* @extends AggregateRootTestCase<ShoppingCartId, ShoppingCart>
*/
abstract class ShoppingCartTestCase extends AggregateRootTestCase
{
protected function newAggregateRootId(): ShoppingCartId
Expand All @@ -22,7 +25,6 @@ protected function aggregateRootClassName(): string

public function handle(Closure $closure): void
{
/** @var ShoppingCart $aggregate */
$aggregate = $this->repository->retrieve($this->aggregateRootId);
$closure($aggregate);
$this->repository->persist($aggregate);
Expand Down