From 46328d2d631d8af0abb6daf18243a8a05c17985d Mon Sep 17 00:00:00 2001 From: David Badura Date: Tue, 6 Feb 2024 09:30:15 +0100 Subject: [PATCH] fix tests --- baseline.xml | 2 +- phpstan-baseline.neon | 2 +- src/Console/OutputStyle.php | 4 +- tests/Benchmark/SimpleSetupBench.php | 2 - tests/Benchmark/SnapshotsBench.php | 2 - tests/Benchmark/SplitStreamBench.php | 2 - tests/Benchmark/SyncProjectionistBench.php | 2 - tests/Benchmark/blackfire.php | 2 - .../Console/Command/OutboxInfoCommandTest.php | 5 +- .../Command/ShowAggregateCommandTest.php | 4 +- tests/Unit/Console/OutputStyleTest.php | 3 +- tests/Unit/EventBus/HeaderNotFoundTest.php | 6 +- tests/Unit/EventBus/MessageTest.php | 15 +++-- tests/Unit/Outbox/DoctrineOutboxStoreTest.php | 15 +---- .../RecalculatePlayheadMiddlewareTest.php | 23 ++++---- tests/Unit/Pipeline/PipelineTest.php | 11 ++-- .../Unit/Repository/DefaultRepositoryTest.php | 56 +++++++++---------- tests/Unit/Store/DoctrineDbalStoreTest.php | 15 ++--- 18 files changed, 70 insertions(+), 101 deletions(-) diff --git a/baseline.xml b/baseline.xml index 09621b43a..258e72349 100644 --- a/baseline.xml +++ b/baseline.xml @@ -192,7 +192,7 @@ 'bar', - 'aggregateClass' => Profile::class, + 'aggregateName' => 'profile', 'aggregateId' => '1', 'playhead' => 3, 'recordedOn' => $recordedAt, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7acd5c954..19fe62935 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,7 +6,7 @@ parameters: path: src/Console/DoctrineHelper.php - - message: "#^Method Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\:\\:headers\\(\\) should return array\\{aggregateClass\\?\\: class\\-string\\, aggregateId\\?\\: string, playhead\\?\\: int\\<1, max\\>, recordedOn\\?\\: DateTimeImmutable, newStreamStart\\?\\: bool, archived\\?\\: bool\\} but returns non\\-empty\\-array\\\\.$#" + message: "#^Method Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\:\\:headers\\(\\) should return array\\{aggregateName\\?\\: string, aggregateId\\?\\: string, playhead\\?\\: int\\<1, max\\>, recordedOn\\?\\: DateTimeImmutable, newStreamStart\\?\\: bool, archived\\?\\: bool\\} but returns non\\-empty\\-array\\\\.$#" count: 1 path: src/EventBus/Message.php diff --git a/src/Console/OutputStyle.php b/src/Console/OutputStyle.php index c2f908386..8e5ad0a5f 100644 --- a/src/Console/OutputStyle.php +++ b/src/Console/OutputStyle.php @@ -24,14 +24,14 @@ public function message(EventSerializer $serializer, Message $message): void $this->horizontalTable([ 'eventClass', - 'aggregateClass', + 'aggregateName', 'aggregateId', 'playhead', 'recordedOn', ], [ [ $event::class, - $message->aggregateClass(), + $message->aggregateName(), $message->aggregateId(), $message->playhead(), $message->recordedOn()->format(DateTimeInterface::ATOM), diff --git a/tests/Benchmark/SimpleSetupBench.php b/tests/Benchmark/SimpleSetupBench.php index c529aa527..f7d9c2be8 100644 --- a/tests/Benchmark/SimpleSetupBench.php +++ b/tests/Benchmark/SimpleSetupBench.php @@ -9,7 +9,6 @@ use Patchlevel\EventSourcing\Aggregate\AggregateRootId; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\EventBus; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; use Patchlevel\EventSourcing\Repository\Repository; use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector; @@ -50,7 +49,6 @@ public function setUp(): void $this->store = new DoctrineDbalStore( $connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']), 'eventstore', ); diff --git a/tests/Benchmark/SnapshotsBench.php b/tests/Benchmark/SnapshotsBench.php index 4ccefc3f6..e970affc4 100644 --- a/tests/Benchmark/SnapshotsBench.php +++ b/tests/Benchmark/SnapshotsBench.php @@ -9,7 +9,6 @@ use Patchlevel\EventSourcing\Aggregate\AggregateRootId; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\EventBus; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; use Patchlevel\EventSourcing\Repository\Repository; use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector; @@ -56,7 +55,6 @@ public function setUp(): void $this->store = new DoctrineDbalStore( $connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']), 'eventstore', ); diff --git a/tests/Benchmark/SplitStreamBench.php b/tests/Benchmark/SplitStreamBench.php index 7af6ddf48..712be95dd 100644 --- a/tests/Benchmark/SplitStreamBench.php +++ b/tests/Benchmark/SplitStreamBench.php @@ -10,7 +10,6 @@ use Patchlevel\EventSourcing\EventBus\Decorator\SplitStreamDecorator; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\EventBus; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; use Patchlevel\EventSourcing\Repository\Repository; @@ -55,7 +54,6 @@ public function setUp(): void $this->store = new DoctrineDbalStore( $connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']), 'eventstore', ); diff --git a/tests/Benchmark/SyncProjectionistBench.php b/tests/Benchmark/SyncProjectionistBench.php index 64b723d64..535fe20f7 100644 --- a/tests/Benchmark/SyncProjectionistBench.php +++ b/tests/Benchmark/SyncProjectionistBench.php @@ -9,7 +9,6 @@ use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\EventBus; use Patchlevel\EventSourcing\Lock\DoctrineDbalStoreSchemaAdapter; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore; use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist; use Patchlevel\EventSourcing\Projection\Projectionist\SyncProjectionistEventBusWrapper; @@ -58,7 +57,6 @@ public function setUp(): void $this->store = new DoctrineDbalStore( $connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']), 'eventstore', ); diff --git a/tests/Benchmark/blackfire.php b/tests/Benchmark/blackfire.php index da71ebf9b..a4bacaaaf 100644 --- a/tests/Benchmark/blackfire.php +++ b/tests/Benchmark/blackfire.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Driver\PDO\SQLite\Driver; use Doctrine\DBAL\DriverManager; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector; use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer; @@ -31,7 +30,6 @@ $store = new DoctrineDbalStore( $connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']), 'eventstore', ); diff --git a/tests/Unit/Console/Command/OutboxInfoCommandTest.php b/tests/Unit/Console/Command/OutboxInfoCommandTest.php index 39ad18537..32e65cb35 100644 --- a/tests/Unit/Console/Command/OutboxInfoCommandTest.php +++ b/tests/Unit/Console/Command/OutboxInfoCommandTest.php @@ -11,7 +11,6 @@ use Patchlevel\EventSourcing\Serializer\Encoder\Encoder; use Patchlevel\EventSourcing\Serializer\EventSerializer; use Patchlevel\EventSourcing\Serializer\SerializedEvent; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use PHPUnit\Framework\TestCase; @@ -31,7 +30,7 @@ public function testSuccessful(): void $store = $this->prophesize(OutboxStore::class); $store->retrieveOutboxMessages(null)->willReturn([ Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn(new DateTimeImmutable()), @@ -69,7 +68,7 @@ public function testSuccessfulWithLimit(): void $store = $this->prophesize(OutboxStore::class); $store->retrieveOutboxMessages(100)->willReturn([ Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn(new DateTimeImmutable()), diff --git a/tests/Unit/Console/Command/ShowAggregateCommandTest.php b/tests/Unit/Console/Command/ShowAggregateCommandTest.php index 2f2d8853d..50cd2401e 100644 --- a/tests/Unit/Console/Command/ShowAggregateCommandTest.php +++ b/tests/Unit/Console/Command/ShowAggregateCommandTest.php @@ -38,7 +38,7 @@ public function testSuccessful(): void $store->load(new Criteria(Profile::class, '1'))->willReturn( new ArrayStream([ Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn(new DateTimeImmutable()), @@ -214,7 +214,7 @@ public function testInteractiveSuccessful(): void $store->load(new Criteria(Profile::class, '1'))->willReturn( new ArrayStream([ Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn(new DateTimeImmutable()), diff --git a/tests/Unit/Console/OutputStyleTest.php b/tests/Unit/Console/OutputStyleTest.php index 9137509c2..4b6dc6df0 100644 --- a/tests/Unit/Console/OutputStyleTest.php +++ b/tests/Unit/Console/OutputStyleTest.php @@ -11,7 +11,6 @@ use Patchlevel\EventSourcing\Serializer\EventSerializer; use Patchlevel\EventSourcing\Serializer\SerializedEvent; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; @@ -41,7 +40,7 @@ public function testWrite(): void )); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn(new DateTimeImmutable()); diff --git a/tests/Unit/EventBus/HeaderNotFoundTest.php b/tests/Unit/EventBus/HeaderNotFoundTest.php index 477e550e7..129f72a9c 100644 --- a/tests/Unit/EventBus/HeaderNotFoundTest.php +++ b/tests/Unit/EventBus/HeaderNotFoundTest.php @@ -10,11 +10,11 @@ /** @covers \Patchlevel\EventSourcing\EventBus\HeaderNotFound */ final class HeaderNotFoundTest extends TestCase { - public function testAggregateClass(): void + public function testAggregateName(): void { self::assertSame( - 'message header "aggregateClass" is not defined', - HeaderNotFound::aggregateClass()->getMessage(), + 'message header "aggregateName" is not defined', + HeaderNotFound::aggregateName()->getMessage(), ); } diff --git a/tests/Unit/EventBus/MessageTest.php b/tests/Unit/EventBus/MessageTest.php index 70d135e6b..0cb1901c5 100644 --- a/tests/Unit/EventBus/MessageTest.php +++ b/tests/Unit/EventBus/MessageTest.php @@ -9,7 +9,6 @@ use Patchlevel\EventSourcing\EventBus\HeaderNotFound; use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\Attributes\DataProvider; @@ -34,9 +33,9 @@ public function testCreateMessageWithAggregateHeader(): void { $message = Message::create(new class { }) - ->withAggregateClass(Profile::class); + ->withAggregateName('profile'); - self::assertSame(Profile::class, $message->aggregateClass()); + self::assertSame('profile', $message->aggregateName()); } public function testCreateMessageWithAggregateIdHeader(): void @@ -143,7 +142,7 @@ public function testAllHeaders(): void $message = Message::create(new class { }) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(3) ->withRecordedOn($recordedAt) @@ -154,7 +153,7 @@ public function testAllHeaders(): void self::assertSame( [ 'foo' => 'bar', - 'aggregateClass' => Profile::class, + 'aggregateName' => 'profile', 'aggregateId' => '1', 'playhead' => 3, 'recordedOn' => $recordedAt, @@ -187,7 +186,7 @@ public function testCreateWithAllHeaders(): void }, [ 'foo' => 'bar', - 'aggregateClass' => Profile::class, + 'aggregateName' => 'profile', 'aggregateId' => '1', 'playhead' => 3, 'recordedOn' => $recordedAt, @@ -199,7 +198,7 @@ public function testCreateWithAllHeaders(): void self::assertSame( [ 'foo' => 'bar', - 'aggregateClass' => Profile::class, + 'aggregateName' => 'profile', 'aggregateId' => '1', 'playhead' => 3, 'recordedOn' => $recordedAt, @@ -224,7 +223,7 @@ public function testHeaderNotFound(string $headerName): void /** @return Generator */ public static function provideHeaderNotFound(): Generator { - yield 'aggregateClass' => ['aggregateClass']; + yield 'aggregateName' => ['aggregateName']; yield 'aggregateId' => ['aggregateId']; yield 'playhead' => ['playhead']; yield 'recordedOn' => ['recordedOn']; diff --git a/tests/Unit/Outbox/DoctrineOutboxStoreTest.php b/tests/Unit/Outbox/DoctrineOutboxStoreTest.php index 42e26e086..1929f1d54 100644 --- a/tests/Unit/Outbox/DoctrineOutboxStoreTest.php +++ b/tests/Unit/Outbox/DoctrineOutboxStoreTest.php @@ -14,13 +14,11 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Types; use Patchlevel\EventSourcing\EventBus\Message; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry; use Patchlevel\EventSourcing\Outbox\DoctrineOutboxStore; use Patchlevel\EventSourcing\Serializer\EventSerializer; use Patchlevel\EventSourcing\Serializer\SerializedEvent; use Patchlevel\EventSourcing\Store\WrongQueryResult; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; @@ -36,7 +34,7 @@ public function testSaveOutboxMessage(): void { $recordedOn = new DateTimeImmutable(); $message = Message::create(new ProfileCreated(ProfileId::fromString('1'), Email::fromString('s'))) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn($recordedOn) @@ -73,7 +71,6 @@ public function testSaveOutboxMessage(): void $doctrineOutboxStore = new DoctrineOutboxStore( $mockedConnection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), ); $doctrineOutboxStore->saveOutboxMessage($message); @@ -83,7 +80,7 @@ public function testMarkOutboxMessageConsumed(): void { $recordedOn = new DateTimeImmutable(); $message = Message::create(new ProfileCreated(ProfileId::fromString('1'), Email::fromString('s'))) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn($recordedOn) @@ -110,7 +107,6 @@ public function testMarkOutboxMessageConsumed(): void $doctrineOutboxStore = new DoctrineOutboxStore( $mockedConnection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), ); $doctrineOutboxStore->markOutboxMessageConsumed($message); @@ -132,7 +128,6 @@ public function testCountOutboxMessages(): void $doctrineOutboxStore = new DoctrineOutboxStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), ); $result = $doctrineOutboxStore->countOutboxMessages(); @@ -155,7 +150,6 @@ public function testCountOutboxMessagesFailure(): void $doctrineOutboxStore = new DoctrineOutboxStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), ); $this->expectException(WrongQueryResult::class); @@ -183,7 +177,6 @@ public function testRetrieveOutboxMessagesNoResult(): void $doctrineOutboxStore = new DoctrineOutboxStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), ); $messages = $doctrineOutboxStore->retrieveOutboxMessages(); @@ -195,7 +188,7 @@ public function testRetrieveOutboxMessages(): void $recordedOn = new DateTimeImmutable(); $event = new ProfileCreated(ProfileId::fromString('1'), Email::fromString('s')); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn($recordedOn) @@ -233,7 +226,6 @@ public function testRetrieveOutboxMessages(): void $doctrineOutboxStore = new DoctrineOutboxStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), ); $messages = $doctrineOutboxStore->retrieveOutboxMessages(); @@ -248,7 +240,6 @@ public function testConfigureSchema(): void $doctrineOutboxStore = new DoctrineOutboxStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), ); $table = $this->prophesize(Table::class); diff --git a/tests/Unit/Pipeline/Middleware/RecalculatePlayheadMiddlewareTest.php b/tests/Unit/Pipeline/Middleware/RecalculatePlayheadMiddlewareTest.php index 921391d6d..05040a979 100644 --- a/tests/Unit/Pipeline/Middleware/RecalculatePlayheadMiddlewareTest.php +++ b/tests/Unit/Pipeline/Middleware/RecalculatePlayheadMiddlewareTest.php @@ -7,7 +7,6 @@ use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; @@ -25,14 +24,14 @@ public function testRecalculatePlayhead(): void ); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(5); $result = $middleware($message); self::assertCount(1, $result); - self::assertSame(Profile::class, $result[0]->aggregateClass()); + self::assertSame('profile', $result[0]->aggregateName()); self::assertSame(1, $result[0]->playhead()); } @@ -46,7 +45,7 @@ public function testRecalculatePlayheadWithSamePlayhead(): void ); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1); @@ -65,24 +64,24 @@ public function testRecalculateMultipleMessages(): void ); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(5); $result = $middleware($message); self::assertCount(1, $result); - self::assertSame(Profile::class, $result[0]->aggregateClass()); + self::assertSame('profile', $result[0]->aggregateName()); self::assertSame(1, $result[0]->playhead()); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(8); $result = $middleware($message); self::assertCount(1, $result); - self::assertSame(Profile::class, $result[0]->aggregateClass()); + self::assertSame('profile', $result[0]->aggregateName()); self::assertSame(2, $result[0]->playhead()); } @@ -96,17 +95,17 @@ public function testReset(): void ); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(5); $result = $middleware($message); self::assertCount(1, $result); - self::assertSame(Profile::class, $result[0]->aggregateClass()); + self::assertSame('profile', $result[0]->aggregateName()); self::assertSame(1, $result[0]->playhead()); $message = Message::create($event) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(8); @@ -114,7 +113,7 @@ public function testReset(): void $result = $middleware($message); self::assertCount(1, $result); - self::assertSame(Profile::class, $result[0]->aggregateClass()); + self::assertSame('profile', $result[0]->aggregateName()); self::assertSame(1, $result[0]->playhead()); } } diff --git a/tests/Unit/Pipeline/PipelineTest.php b/tests/Unit/Pipeline/PipelineTest.php index 8eccf29f0..c04129792 100644 --- a/tests/Unit/Pipeline/PipelineTest.php +++ b/tests/Unit/Pipeline/PipelineTest.php @@ -11,7 +11,6 @@ use Patchlevel\EventSourcing\Pipeline\Source\InMemorySource; use Patchlevel\EventSourcing\Pipeline\Target\InMemoryTarget; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; @@ -106,7 +105,7 @@ private function messages(): array Email::fromString('hallo@patchlevel.de'), ), ) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1), @@ -115,7 +114,7 @@ private function messages(): array ProfileId::fromString('1'), ), ) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(2), @@ -124,7 +123,7 @@ private function messages(): array ProfileId::fromString('1'), ), ) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(3), @@ -134,7 +133,7 @@ private function messages(): array Email::fromString('hallo@patchlevel.de'), ), ) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('2') ->withPlayhead(1), @@ -143,7 +142,7 @@ private function messages(): array ProfileId::fromString('2'), ), ) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('2') ->withPlayhead(2), ]; diff --git a/tests/Unit/Repository/DefaultRepositoryTest.php b/tests/Unit/Repository/DefaultRepositoryTest.php index 3602c1c99..11da91146 100644 --- a/tests/Unit/Repository/DefaultRepositoryTest.php +++ b/tests/Unit/Repository/DefaultRepositoryTest.php @@ -45,7 +45,7 @@ public function testSaveAggregate(): void $store = $this->prophesize(Store::class); $store->save( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -56,7 +56,7 @@ public function testSaveAggregate(): void return $message->playhead() === 1; }), Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -76,7 +76,7 @@ public function testSaveAggregate(): void $eventBus = $this->prophesize(EventBus::class); $eventBus->dispatch( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -87,7 +87,7 @@ public function testSaveAggregate(): void return $message->playhead() === 1; }), Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -120,7 +120,7 @@ public function testUpdateAggregate(): void $store = $this->prophesize(Store::class); $store->save( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -134,7 +134,7 @@ public function testUpdateAggregate(): void $store->save( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -154,7 +154,7 @@ public function testUpdateAggregate(): void $eventBus = $this->prophesize(EventBus::class); $eventBus->dispatch( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -168,7 +168,7 @@ public function testUpdateAggregate(): void $eventBus->dispatch( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -203,7 +203,7 @@ public function testDecorator(): void $store = $this->prophesize(Store::class); $store->save( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -227,7 +227,7 @@ public function testDecorator(): void $eventBus = $this->prophesize(EventBus::class); $eventBus->dispatch( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -293,7 +293,7 @@ public function testSaveAggregateWithEmptyEventStream(): void $store = $this->prophesize(Store::class); $store->save( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -313,7 +313,7 @@ public function testSaveAggregateWithEmptyEventStream(): void $eventBus = $this->prophesize(EventBus::class); $eventBus->dispatch( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -488,7 +488,7 @@ public function testSaveAggregateWithSplitStream(): void $store->willImplement(ArchivableStore::class); $store->save( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -499,7 +499,7 @@ public function testSaveAggregateWithSplitStream(): void return $message->playhead() === 1; }), Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -510,7 +510,7 @@ public function testSaveAggregateWithSplitStream(): void return $message->playhead() === 2; }), Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -521,7 +521,7 @@ public function testSaveAggregateWithSplitStream(): void return $message->playhead() === 3; }), )->shouldBeCalled(); - $store->archiveMessages(Profile::class, '1', 3)->shouldBeCalledOnce(); + $store->archiveMessages('profile', '1', 3)->shouldBeCalledOnce(); $store->transactional(Argument::any())->will( /** @param array{0: callable} $args */ static fn (array $args): mixed => $args[0]() @@ -530,7 +530,7 @@ public function testSaveAggregateWithSplitStream(): void $eventBus = $this->prophesize(EventBus::class); $eventBus->dispatch( Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -541,7 +541,7 @@ public function testSaveAggregateWithSplitStream(): void return $message->playhead() === 1; }), Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -552,7 +552,7 @@ public function testSaveAggregateWithSplitStream(): void return $message->playhead() === 2; }), Argument::that(static function (Message $message) { - if ($message->aggregateClass() !== Profile::class) { + if ($message->aggregateName() !== 'profile') { return false; } @@ -586,7 +586,7 @@ public function testLoadAggregate(): void { $store = $this->prophesize(Store::class); $store->load(new Criteria( - Profile::class, + 'profile', '1', ))->willReturn(new ArrayStream([ Message::create( @@ -617,7 +617,7 @@ public function testLoadAggregateTwice(): void { $store = $this->prophesize(Store::class); $store->load(new Criteria( - Profile::class, + 'profile', '1', ))->willReturn( new ArrayStream([ @@ -659,7 +659,7 @@ public function testAggregateNotFound(): void $store = $this->prophesize(Store::class); $store->load(new Criteria( - Profile::class, + 'profile', '1', ))->willReturn(new ArrayStream()); @@ -678,7 +678,7 @@ public function testHasAggregate(): void { $store = $this->prophesize(Store::class); $store->count(new Criteria( - Profile::class, + 'profile', '1', ))->willReturn(1); @@ -697,7 +697,7 @@ public function testNotHasAggregate(): void { $store = $this->prophesize(Store::class); $store->count(new Criteria( - Profile::class, + 'profile', '1', ))->willReturn(0); @@ -723,7 +723,7 @@ public function testLoadAggregateWithSnapshot(): void $store = $this->prophesize(Store::class); $store->load(new Criteria( - ProfileWithSnapshot::class, + 'profile_with_snapshot', '1', null, 1, @@ -757,7 +757,7 @@ public function testLoadAggregateWithSnapshotFirstTime(): void $store = $this->prophesize(Store::class); $store->load( new Criteria( - ProfileWithSnapshot::class, + 'profile_with_snapshot', '1', ), )->willReturn( @@ -816,7 +816,7 @@ public function testLoadAggregateWithSnapshotAndSaveNewVersion(): void $store = $this->prophesize(Store::class); $store->load( new Criteria( - ProfileWithSnapshot::class, + 'profile_with_snapshot', '1', null, 1, @@ -867,7 +867,7 @@ public function testLoadAggregateWithSnapshotAndSaveNewVersion(): void public function testLoadAggregateWithoutSnapshot(): void { $store = $this->prophesize(Store::class); - $store->load(new Criteria(ProfileWithSnapshot::class, '1')) + $store->load(new Criteria('profile_with_snapshot', '1')) ->willReturn(new ArrayStream([ Message::create( new ProfileCreated( diff --git a/tests/Unit/Store/DoctrineDbalStoreTest.php b/tests/Unit/Store/DoctrineDbalStoreTest.php index 47f7be242..684d1b58d 100644 --- a/tests/Unit/Store/DoctrineDbalStoreTest.php +++ b/tests/Unit/Store/DoctrineDbalStoreTest.php @@ -18,13 +18,11 @@ use Doctrine\DBAL\Types\Types; use EmptyIterator; use Patchlevel\EventSourcing\EventBus\Message; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry; use Patchlevel\EventSourcing\Serializer\EventSerializer; use Patchlevel\EventSourcing\Serializer\SerializedEvent; use Patchlevel\EventSourcing\Store\CriteriaBuilder; use Patchlevel\EventSourcing\Store\DoctrineDbalStore; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\Attributes\RequiresPhp; @@ -74,13 +72,12 @@ public function testLoadWithNoEvents(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), 'eventstore', ); $stream = $doctrineDbalStore->load( (new CriteriaBuilder()) - ->aggregateClass(Profile::class) + ->aggregateName('profile') ->aggregateId('1') ->fromPlayhead(0) ->archived(false) @@ -144,13 +141,12 @@ public function testLoadWithOneEvent(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), 'eventstore', ); $stream = $doctrineDbalStore->load( (new CriteriaBuilder()) - ->aggregateClass(Profile::class) + ->aggregateName('profile') ->aggregateId('1') ->fromPlayhead(0) ->archived(false) @@ -190,7 +186,6 @@ public function testTransactional(): void $store = new DoctrineDbalStore( $connection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), 'eventstore', ); @@ -201,7 +196,7 @@ public function testSaveWithOneEvent(): void { $recordedOn = new DateTimeImmutable(); $message = Message::create(new ProfileCreated(ProfileId::fromString('1'), Email::fromString('s'))) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('1') ->withPlayhead(1) ->withRecordedOn($recordedOn) @@ -236,7 +231,6 @@ public function testSaveWithOneEvent(): void $singleTableStore = new DoctrineDbalStore( $mockedConnection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), 'eventstore', ); $singleTableStore->save($message); @@ -266,9 +260,8 @@ public function testArchiveMessages(): void $singleTableStore = new DoctrineDbalStore( $mockedConnection->reveal(), $serializer->reveal(), - new AggregateRootRegistry(['profile' => Profile::class]), 'eventstore', ); - $singleTableStore->archiveMessages(Profile::class, '1', 1); + $singleTableStore->archiveMessages('profile', '1', 1); } }