diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bb45b9abb..9cff1d479 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,9 +13,7 @@ requireCoverageMetadata="false" > - - ./tests/Unit - + ./tests/Integration diff --git a/src/EventBus/HeaderNotFound.php b/src/EventBus/HeaderNotFound.php index c7d4edfe7..cf5367179 100644 --- a/src/EventBus/HeaderNotFound.php +++ b/src/EventBus/HeaderNotFound.php @@ -14,9 +14,9 @@ private function __construct( parent::__construct(sprintf('message header "%s" is not defined', $name)); } - public static function aggregateClass(): self + public static function aggregateName(): self { - return new self(Message::HEADER_AGGREGATE_CLASS); + return new self(Message::HEADER_AGGREGATE_NAME); } public static function aggregateId(): self diff --git a/src/EventBus/Message.php b/src/EventBus/Message.php index 3236d14cc..6b4e559ff 100644 --- a/src/EventBus/Message.php +++ b/src/EventBus/Message.php @@ -5,7 +5,6 @@ namespace Patchlevel\EventSourcing\EventBus; use DateTimeImmutable; -use Patchlevel\EventSourcing\Aggregate\AggregateRoot; use function array_key_exists; use function array_keys; @@ -13,19 +12,18 @@ /** * @template-covariant T of object * @psalm-immutable - * @psalm-type Headers = array{aggregateClass?: class-string, aggregateId?:string, playhead?:positive-int, recordedOn?: DateTimeImmutable, newStreamStart?: bool, archived?: bool} + * @psalm-type Headers = array{aggregateName?: string, aggregateId?:string, playhead?:positive-int, recordedOn?: DateTimeImmutable, newStreamStart?: bool, archived?: bool} */ final class Message { - public const HEADER_AGGREGATE_CLASS = 'aggregateClass'; + public const HEADER_AGGREGATE_NAME = 'aggregateName'; public const HEADER_AGGREGATE_ID = 'aggregateId'; public const HEADER_PLAYHEAD = 'playhead'; public const HEADER_RECORDED_ON = 'recordedOn'; public const HEADER_ARCHIVED = 'archived'; public const HEADER_NEW_STREAM_START = 'newStreamStart'; - /** @var class-string|null */ - private string|null $aggregateClass = null; + private string|null $aggregateName = null; private string|null $aggregateId = null; /** @var positive-int|null */ private int|null $playhead = null; @@ -61,26 +59,24 @@ public function event(): object } /** - * @return class-string - * * @throws HeaderNotFound */ - public function aggregateClass(): string + public function aggregateName(): string { - $value = $this->aggregateClass; + $value = $this->aggregateName; if ($value === null) { - throw HeaderNotFound::aggregateClass(); + throw HeaderNotFound::aggregateName(); } return $value; } - /** @param class-string $value */ - public function withAggregateClass(string $value): self + /** @param string $value */ + public function withAggregateName(string $value): self { $message = clone $this; - $message->aggregateClass = $value; + $message->aggregateName = $value; return $message; } @@ -214,8 +210,8 @@ public function headers(): array { $headers = $this->customHeaders; - if ($this->aggregateClass !== null) { - $headers[self::HEADER_AGGREGATE_CLASS] = $this->aggregateClass; + if ($this->aggregateName !== null) { + $headers[self::HEADER_AGGREGATE_NAME] = $this->aggregateName; } if ($this->aggregateId !== null) { @@ -241,8 +237,8 @@ public static function createWithHeaders(object $event, array $headers): self { $message = self::create($event); - if (array_key_exists(self::HEADER_AGGREGATE_CLASS, $headers)) { - $message = $message->withAggregateClass($headers[self::HEADER_AGGREGATE_CLASS]); + if (array_key_exists(self::HEADER_AGGREGATE_NAME, $headers)) { + $message = $message->withAggregateName($headers[self::HEADER_AGGREGATE_NAME]); } if (array_key_exists(self::HEADER_AGGREGATE_ID, $headers)) { @@ -266,7 +262,7 @@ public static function createWithHeaders(object $event, array $headers): self } unset( - $headers[self::HEADER_AGGREGATE_CLASS], + $headers[self::HEADER_AGGREGATE_NAME], $headers[self::HEADER_AGGREGATE_ID], $headers[self::HEADER_PLAYHEAD], $headers[self::HEADER_RECORDED_ON], diff --git a/src/Outbox/DoctrineOutboxStore.php b/src/Outbox/DoctrineOutboxStore.php index 3cb014a98..1d0073134 100644 --- a/src/Outbox/DoctrineOutboxStore.php +++ b/src/Outbox/DoctrineOutboxStore.php @@ -24,7 +24,6 @@ final class DoctrineOutboxStore implements OutboxStore, SchemaConfigurator public function __construct( private readonly Connection $connection, private readonly EventSerializer $serializer, - private readonly AggregateRootRegistry $aggregateRootRegistry, private readonly string $outboxTable = 'outbox', ) { } @@ -41,7 +40,7 @@ function (Connection $connection) use ($messages): void { $connection->insert( $this->outboxTable, [ - 'aggregate' => $this->aggregateRootRegistry->aggregateName($message->aggregateClass()), + 'aggregate' => $message->aggregateName(), 'aggregate_id' => $message->aggregateId(), 'playhead' => $message->playhead(), 'event' => $data->name, @@ -77,7 +76,7 @@ function (array $data) use ($platform) { $event = $this->serializer->deserialize(new SerializedEvent($data['event'], $data['payload'])); return Message::create($event) - ->withAggregateClass($this->aggregateRootRegistry->aggregateClass($data['aggregate'])) + ->withAggregateName($data['aggregate']) ->withAggregateId($data['aggregate_id']) ->withPlayhead(DoctrineHelper::normalizePlayhead($data['playhead'], $platform)) ->withRecordedOn(DoctrineHelper::normalizeRecordedOn($data['recorded_on'], $platform)) @@ -95,7 +94,7 @@ function (Connection $connection) use ($messages): void { $connection->delete( $this->outboxTable, [ - 'aggregate' => $this->aggregateRootRegistry->aggregateName($message->aggregateClass()), + 'aggregate' => $message->aggregateName(), 'aggregate_id' => $message->aggregateId(), 'playhead' => $message->playhead(), ], diff --git a/src/Pipeline/Middleware/RecalculatePlayheadMiddleware.php b/src/Pipeline/Middleware/RecalculatePlayheadMiddleware.php index d2f5addea..2090d69d9 100644 --- a/src/Pipeline/Middleware/RecalculatePlayheadMiddleware.php +++ b/src/Pipeline/Middleware/RecalculatePlayheadMiddleware.php @@ -4,20 +4,19 @@ namespace Patchlevel\EventSourcing\Pipeline\Middleware; -use Patchlevel\EventSourcing\Aggregate\AggregateRoot; use Patchlevel\EventSourcing\EventBus\Message; use function array_key_exists; final class RecalculatePlayheadMiddleware implements Middleware { - /** @var array, array> */ + /** @var array> */ private array $index = []; /** @return list */ public function __invoke(Message $message): array { - $playhead = $this->nextPlayhead($message->aggregateClass(), $message->aggregateId()); + $playhead = $this->nextPlayhead($message->aggregateName(), $message->aggregateId()); if ($message->playhead() === $playhead) { return [$message]; @@ -29,22 +28,20 @@ public function __invoke(Message $message): array } /** - * @param class-string $aggregateClass - * * @return positive-int */ - private function nextPlayhead(string $aggregateClass, string $aggregateId): int + private function nextPlayhead(string $aggregateName, string $aggregateId): int { - if (!array_key_exists($aggregateClass, $this->index)) { - $this->index[$aggregateClass] = []; + if (!array_key_exists($aggregateName, $this->index)) { + $this->index[$aggregateName] = []; } - if (!array_key_exists($aggregateId, $this->index[$aggregateClass])) { - $this->index[$aggregateClass][$aggregateId] = 1; + if (!array_key_exists($aggregateId, $this->index[$aggregateName])) { + $this->index[$aggregateName][$aggregateId] = 1; } else { - $this->index[$aggregateClass][$aggregateId]++; + $this->index[$aggregateName][$aggregateId]++; } - return $this->index[$aggregateClass][$aggregateId]; + return $this->index[$aggregateName][$aggregateId]; } } diff --git a/src/Repository/DefaultRepository.php b/src/Repository/DefaultRepository.php index e9dd649c1..2f8d8f800 100644 --- a/src/Repository/DefaultRepository.php +++ b/src/Repository/DefaultRepository.php @@ -68,7 +68,7 @@ public function load(AggregateRootId $id): AggregateRoot $this->logger->debug( sprintf( 'Repository: Aggregate "%s" with the id "%s" loaded from snapshot.', - $this->metadata->className, + $this->metadata->name, $id->toString(), ), ); @@ -78,7 +78,7 @@ public function load(AggregateRootId $id): AggregateRoot $this->logger->error( sprintf( 'Repository: Aggregate "%s" with the id "%s" could not be rebuild from snapshot.', - $this->metadata->className, + $this->metadata->name, $id->toString(), ), ); @@ -88,7 +88,7 @@ public function load(AggregateRootId $id): AggregateRoot $this->logger->debug( sprintf( 'Repository: Snapshot for aggregate "%s" with the id "%s" not found.', - $this->metadata->className, + $this->metadata->name, $id->toString(), ), ); @@ -96,7 +96,7 @@ public function load(AggregateRootId $id): AggregateRoot $this->logger->debug( sprintf( 'Repository: Snapshot for aggregate "%s" with the id "%s" is invalid.', - $this->metadata->className, + $this->metadata->name, $id->toString(), ), ); @@ -104,7 +104,7 @@ public function load(AggregateRootId $id): AggregateRoot } $criteria = (new CriteriaBuilder()) - ->aggregateClass($this->metadata->className) + ->aggregateName($this->metadata->name) ->aggregateId($id->toString()) ->archived(false) ->build(); @@ -120,7 +120,7 @@ public function load(AggregateRootId $id): AggregateRoot $this->logger->debug( sprintf( 'Repository: Aggregate "%s" with the id "%s" not found.', - $this->metadata->className, + $this->metadata->name, $id->toString(), ), ); @@ -145,7 +145,7 @@ public function load(AggregateRootId $id): AggregateRoot $this->logger->debug( sprintf( 'Repository: Aggregate "%s" with the id "%s" loaded from store.', - $this->metadata->className, + $this->metadata->name, $id->toString(), ), ); @@ -156,7 +156,7 @@ public function load(AggregateRootId $id): AggregateRoot public function has(AggregateRootId $id): bool { $criteria = (new CriteriaBuilder()) - ->aggregateClass($this->metadata->className) + ->aggregateName($this->metadata->name) ->aggregateId($id->toString()) ->build(); @@ -167,6 +167,7 @@ public function has(AggregateRootId $id): bool public function save(AggregateRoot $aggregate): void { $this->assertValidAggregate($aggregate); + $aggregateId = $aggregate->aggregateRootId()->toString(); try { $events = $aggregate->releaseEvents(); @@ -183,8 +184,8 @@ public function save(AggregateRoot $aggregate): void $this->logger->error( sprintf( 'Repository: Aggregate "%s" with the id "%s" is unknown.', - $this->metadata->className, - $aggregate->aggregateRootId()->toString(), + $this->metadata->name, + $aggregateId, ), ); @@ -195,8 +196,8 @@ public function save(AggregateRoot $aggregate): void $this->logger->error( sprintf( 'Repository: Aggregate "%s" with the id "%s" has a playhead mismatch. Expected "%d" but got "%d".', - $this->metadata->className, - $aggregate->aggregateRootId()->toString(), + $this->metadata->name, + $aggregateId, $aggregate->playhead(), $eventCount, ), @@ -213,11 +214,13 @@ public function save(AggregateRoot $aggregate): void $messageDecorator = $this->messageDecorator; $clock = $this->clock; + $aggregateName = $this->metadata->name; + $messages = array_map( - static function (object $event) use ($aggregate, &$playhead, $messageDecorator, $clock) { + static function (object $event) use ($aggregateName, $aggregateId, &$playhead, $messageDecorator, $clock) { $message = Message::create($event) - ->withAggregateClass($aggregate::class) - ->withAggregateId($aggregate->aggregateRootId()->toString()) + ->withAggregateName($aggregateName) + ->withAggregateId($aggregateId) ->withPlayhead(++$playhead) ->withRecordedOn($clock->now()); @@ -230,7 +233,7 @@ static function (object $event) use ($aggregate, &$playhead, $messageDecorator, $events, ); - $this->store->transactional(function () use ($messages, $aggregate, $newAggregate): void { + $this->store->transactional(function () use ($messages, $aggregate, $aggregateId, $newAggregate): void { try { $this->store->save(...$messages); } catch (UniqueConstraintViolation) { @@ -239,7 +242,7 @@ static function (object $event) use ($aggregate, &$playhead, $messageDecorator, sprintf( 'Repository: Aggregate "%s" with the id "%s" already exists.', $aggregate::class, - $aggregate->aggregateRootId()->toString(), + $aggregateId, ), ); @@ -250,7 +253,7 @@ static function (object $event) use ($aggregate, &$playhead, $messageDecorator, sprintf( 'Repository: Aggregate "%s" with the id "%s" is outdated.', $aggregate::class, - $aggregate->aggregateRootId()->toString(), + $aggregateId, ), ); @@ -266,8 +269,8 @@ static function (object $event) use ($aggregate, &$playhead, $messageDecorator, $this->logger->debug( sprintf( 'Repository: Aggregate "%s" with the id "%s" saved.', - $this->metadata->className, - $aggregate->aggregateRootId()->toString(), + $this->metadata->name, + $aggregateId, ), ); } catch (Throwable $exception) { @@ -289,7 +292,7 @@ private function loadFromSnapshot(string $aggregateClass, AggregateRootId $id): $aggregate = $this->snapshotStore->load($aggregateClass, $id); $criteria = (new CriteriaBuilder()) - ->aggregateClass($this->metadata->className) + ->aggregateName($this->metadata->name) ->aggregateId($id->toString()) ->fromPlayhead($aggregate->playhead()) ->build(); @@ -380,7 +383,7 @@ private function archive(Message ...$messages): void } $this->store->archiveMessages( - $lastMessageWithNewStreamStart->aggregateClass(), + $lastMessageWithNewStreamStart->aggregateName(), $lastMessageWithNewStreamStart->aggregateId(), $lastMessageWithNewStreamStart->playhead(), ); @@ -388,7 +391,7 @@ private function archive(Message ...$messages): void $this->logger->debug( sprintf( 'Repository: Archive messages for aggregate "%s" with the id "%s" until playhead "%d".', - $lastMessageWithNewStreamStart->aggregateClass(), + $lastMessageWithNewStreamStart->aggregateName(), $lastMessageWithNewStreamStart->aggregateId(), $lastMessageWithNewStreamStart->playhead(), ), diff --git a/src/Store/ArchivableStore.php b/src/Store/ArchivableStore.php index 8d5e6ef0b..fc4981282 100644 --- a/src/Store/ArchivableStore.php +++ b/src/Store/ArchivableStore.php @@ -4,10 +4,7 @@ namespace Patchlevel\EventSourcing\Store; -use Patchlevel\EventSourcing\Aggregate\AggregateRoot; - interface ArchivableStore { - /** @param class-string $aggregate */ - public function archiveMessages(string $aggregate, string $id, int $untilPlayhead): void; + public function archiveMessages(string $aggregateName, string $aggregateId, int $untilPlayhead): void; } diff --git a/src/Store/Criteria.php b/src/Store/Criteria.php index 31a3608e8..8401633ca 100644 --- a/src/Store/Criteria.php +++ b/src/Store/Criteria.php @@ -4,13 +4,10 @@ namespace Patchlevel\EventSourcing\Store; -use Patchlevel\EventSourcing\Aggregate\AggregateRoot; - final class Criteria { public function __construct( - /** @var class-string|null */ - public readonly string|null $aggregateClass = null, + public readonly string|null $aggregateName = null, public readonly string|null $aggregateId = null, public readonly int|null $fromIndex = null, public readonly int|null $fromPlayhead = null, diff --git a/src/Store/CriteriaBuilder.php b/src/Store/CriteriaBuilder.php index 3d8cd00b9..93d2f0325 100644 --- a/src/Store/CriteriaBuilder.php +++ b/src/Store/CriteriaBuilder.php @@ -4,21 +4,17 @@ namespace Patchlevel\EventSourcing\Store; -use Patchlevel\EventSourcing\Aggregate\AggregateRoot; - final class CriteriaBuilder { - /** @var class-string|null */ - private string|null $aggregateClass = null; + private string|null $aggregateName = null; private string|null $aggregateId = null; private int|null $fromIndex = null; private int|null $fromPlayhead = null; private bool|null $archived = null; - /** @param class-string|null $aggregateClass */ - public function aggregateClass(string|null $aggregateClass): self + public function aggregateName(string|null $aggregateName): self { - $this->aggregateClass = $aggregateClass; + $this->aggregateName = $aggregateName; return $this; } @@ -54,7 +50,7 @@ public function archived(bool|null $archived): self public function build(): Criteria { return new Criteria( - $this->aggregateClass, + $this->aggregateName, $this->aggregateId, $this->fromIndex, $this->fromPlayhead, diff --git a/src/Store/DoctrineDbalStore.php b/src/Store/DoctrineDbalStore.php index 0802f16ee..082866546 100644 --- a/src/Store/DoctrineDbalStore.php +++ b/src/Store/DoctrineDbalStore.php @@ -11,10 +11,8 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; -use Patchlevel\EventSourcing\Aggregate\AggregateRoot; use Patchlevel\EventSourcing\EventBus\HeaderNotFound; use Patchlevel\EventSourcing\EventBus\Message; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry; use Patchlevel\EventSourcing\Schema\SchemaConfigurator; use Patchlevel\EventSourcing\Serializer\EventSerializer; @@ -30,7 +28,6 @@ final class DoctrineDbalStore implements Store, ArchivableStore, SchemaConfigura public function __construct( private readonly Connection $connection, private readonly EventSerializer $serializer, - private readonly AggregateRootRegistry $aggregateRootRegistry, private readonly string $storeTableName = 'eventstore', ) { } @@ -58,7 +55,6 @@ public function load( $builder->getParameterTypes(), ), $this->serializer, - $this->aggregateRootRegistry, $this->connection->getDatabasePlatform(), ); } @@ -86,8 +82,8 @@ public function count(Criteria|null $criteria = null): int private function applyCriteria(QueryBuilder $builder, Criteria $criteria): void { - if ($criteria->aggregateClass !== null) { - $shortName = $this->aggregateRootRegistry->aggregateName($criteria->aggregateClass); + if ($criteria->aggregateName !== null) { + $shortName = $criteria->aggregateName; $builder->andWhere('aggregate = :aggregate'); $builder->setParameter('aggregate', $shortName); } @@ -155,7 +151,7 @@ function (Connection $connection) use ($messages): void { $data = $this->serializer->serialize($message->event()); try { - $parameters[] = $this->aggregateRootRegistry->aggregateName($message->aggregateClass()); + $parameters[] = $message->aggregateName(); $parameters[] = $message->aggregateId(); $parameters[] = $message->playhead(); $parameters[] = $data->name; @@ -203,11 +199,8 @@ public function transactional(Closure $function): void $this->connection->transactional($function); } - /** @param class-string $aggregate */ - public function archiveMessages(string $aggregate, string $id, int $untilPlayhead): void + public function archiveMessages(string $aggregateName, string $aggregateId, int $untilPlayhead): void { - $aggregateName = $this->aggregateRootRegistry->aggregateName($aggregate); - $statement = $this->connection->prepare(sprintf( 'UPDATE %s SET archived = true @@ -219,7 +212,7 @@ public function archiveMessages(string $aggregate, string $id, int $untilPlayhea )); $statement->bindValue('aggregate', $aggregateName); - $statement->bindValue('aggregate_id', $id); + $statement->bindValue('aggregate_id', $aggregateId); $statement->bindValue('playhead', $untilPlayhead); $statement->executeQuery(); diff --git a/src/Store/DoctrineDbalStoreStream.php b/src/Store/DoctrineDbalStoreStream.php index 77a78646a..45c3ca979 100644 --- a/src/Store/DoctrineDbalStoreStream.php +++ b/src/Store/DoctrineDbalStoreStream.php @@ -9,7 +9,6 @@ use Generator; use IteratorAggregate; use Patchlevel\EventSourcing\EventBus\Message; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry; use Patchlevel\EventSourcing\Serializer\EventSerializer; use Patchlevel\EventSourcing\Serializer\SerializedEvent; use Traversable; @@ -29,10 +28,9 @@ final class DoctrineDbalStoreStream implements Stream, IteratorAggregate public function __construct( private readonly Result $result, EventSerializer $serializer, - AggregateRootRegistry $aggregateRootRegistry, AbstractPlatform $platform, ) { - $this->generator = $this->buildGenerator($result, $serializer, $aggregateRootRegistry, $platform); + $this->generator = $this->buildGenerator($result, $serializer, $platform); $this->position = null; $this->index = null; } @@ -87,7 +85,6 @@ public function getIterator(): Traversable private function buildGenerator( Result $result, EventSerializer $serializer, - AggregateRootRegistry $aggregateRootRegistry, AbstractPlatform $platform, ): Generator { /** @var array{id: positive-int, aggregate: string, aggregate_id: string, playhead: int|string, event: string, payload: string, recorded_on: string, custom_headers: string} $data */ @@ -102,7 +99,7 @@ private function buildGenerator( $event = $serializer->deserialize(new SerializedEvent($data['event'], $data['payload'])); yield Message::create($event) - ->withAggregateClass($aggregateRootRegistry->aggregateClass($data['aggregate'])) + ->withAggregateName($data['aggregate']) ->withAggregateId($data['aggregate_id']) ->withPlayhead(DoctrineHelper::normalizePlayhead($data['playhead'], $platform)) ->withRecordedOn(DoctrineHelper::normalizeRecordedOn($data['recorded_on'], $platform)) diff --git a/tests/Integration/BankAccountSplitStream/IntegrationTest.php b/tests/Integration/BankAccountSplitStream/IntegrationTest.php index b8b58a7e4..2fb36598b 100644 --- a/tests/Integration/BankAccountSplitStream/IntegrationTest.php +++ b/tests/Integration/BankAccountSplitStream/IntegrationTest.php @@ -9,7 +9,6 @@ use Patchlevel\EventSourcing\EventBus\Decorator\SplitStreamDecorator; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory; use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore; use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist; @@ -51,7 +50,6 @@ public function testSuccessful(): void $store = new DoctrineDbalStore( $this->connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/Aggregate']), 'eventstore', ); diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index dbf5c6b6b..f08fa4627 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry; -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; @@ -48,7 +47,6 @@ public function testSuccessful(): void $store = new DoctrineDbalStore( $this->connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/Aggregate']), 'eventstore', ); @@ -121,7 +119,6 @@ public function testSnapshot(): void $store = new DoctrineDbalStore( $this->connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/Aggregate']), 'eventstore', ); diff --git a/tests/Integration/Outbox/OutboxTest.php b/tests/Integration/Outbox/OutboxTest.php index 7c864e605..26fd6a4d0 100644 --- a/tests/Integration/Outbox/OutboxTest.php +++ b/tests/Integration/Outbox/OutboxTest.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Outbox\DoctrineOutboxStore; use Patchlevel\EventSourcing\Outbox\EventBusPublisher; use Patchlevel\EventSourcing\Outbox\OutboxEventBus; @@ -48,19 +47,16 @@ public function tearDown(): void public function testSuccessful(): void { $serializer = DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']); - $registry = (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/Aggregate']); $store = new DoctrineDbalStore( $this->connection, $serializer, - $registry, 'eventstore', ); $outboxStore = new DoctrineOutboxStore( $this->connection, $serializer, - $registry, 'outbox', ); @@ -114,7 +110,7 @@ public function testSuccessful(): void $message = $messages[0]; self::assertSame('1', $message->aggregateId()); - self::assertSame(Profile::class, $message->aggregateClass()); + self::assertSame('profile', $message->aggregateName()); self::assertSame(1, $message->playhead()); self::assertEquals( new ProfileCreated(ProfileId::fromString('1'), 'John'), diff --git a/tests/Integration/Pipeline/PipelineChangeStoreTest.php b/tests/Integration/Pipeline/PipelineChangeStoreTest.php index e8ff19beb..f5970c16b 100644 --- a/tests/Integration/Pipeline/PipelineChangeStoreTest.php +++ b/tests/Integration/Pipeline/PipelineChangeStoreTest.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Connection; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; -use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware; use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; use Patchlevel\EventSourcing\Pipeline\Middleware\ReplaceEventMiddleware; @@ -45,12 +44,10 @@ public function tearDown(): void public function testSuccessful(): void { $serializer = DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']); - $aggregateRootRegistry = (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/Aggregate']); $oldStore = new DoctrineDbalStore( $this->connectionOld, $serializer, - $aggregateRootRegistry, 'eventstore', ); @@ -64,7 +61,6 @@ public function testSuccessful(): void $newStore = new DoctrineDbalStore( $this->connectionNew, $serializer, - $aggregateRootRegistry, 'eventstore', ); diff --git a/tests/Integration/Projectionist/ProjectionistTest.php b/tests/Integration/Projectionist/ProjectionistTest.php index 013791a04..7f3923ef7 100644 --- a/tests/Integration/Projectionist/ProjectionistTest.php +++ b/tests/Integration/Projectionist/ProjectionistTest.php @@ -45,7 +45,6 @@ public function testAsync(): void $store = new DoctrineDbalStore( $this->connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']), - (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/Aggregate']), 'eventstore', ); @@ -100,7 +99,6 @@ public function testSync(): void $store = new DoctrineDbalStore( $this->connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']), - $aggregateRegistry, 'eventstore', ); diff --git a/tests/Integration/Store/StoreTest.php b/tests/Integration/Store/StoreTest.php index 81e5ea6d6..b382a576e 100644 --- a/tests/Integration/Store/StoreTest.php +++ b/tests/Integration/Store/StoreTest.php @@ -31,7 +31,6 @@ public function setUp(): void $this->store = new DoctrineDbalStore( $this->connection, DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']), - new AggregateRootRegistry(['profile' => Profile::class]), 'eventstore', ); @@ -52,12 +51,12 @@ public function testSave(): void { $messages = [ Message::create(new ProfileCreated(ProfileId::fromString('test'), 'test')) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('test') ->withPlayhead(1) ->withRecordedOn(new DateTimeImmutable('2020-01-01 00:00:00')), Message::create(new ProfileCreated(ProfileId::fromString('test'), 'test')) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('test') ->withPlayhead(2) ->withRecordedOn(new DateTimeImmutable('2020-01-02 00:00:00')), @@ -92,7 +91,7 @@ public function testSave(): void public function testLoad(): void { $message = Message::create(new ProfileCreated(ProfileId::fromString('test'), 'test')) - ->withAggregateClass(Profile::class) + ->withAggregateName('profile') ->withAggregateId('test') ->withPlayhead(1) ->withRecordedOn(new DateTimeImmutable('2020-01-01 00:00:00'));