diff --git a/deptrac.yaml b/deptrac.yaml index 5798c3dc6..3a0b4c7e4 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -64,10 +64,6 @@ deptrac: value: MetadataMessage - type: layer value: MetadataSubscriber - - name: Pipeline - collectors: - - type: directory - value: src/Pipeline/.* - name: Repository collectors: - type: directory @@ -117,8 +113,10 @@ deptrac: - Attribute - Message Message: + - Aggregate - MetadataMessage - Serializer + - Store Metadata: MetadataAggregate: - Aggregate @@ -134,12 +132,6 @@ deptrac: - Attribute - Metadata - Subscription - Pipeline: - - Aggregate - - EventBus - - Message - - Store - - Subscription Subscription: - Attribute - Clock diff --git a/docs/pages/pipeline.md b/docs/pages/pipeline.md index bbdcced14..d765c8bfc 100644 --- a/docs/pages/pipeline.md +++ b/docs/pages/pipeline.md @@ -10,12 +10,7 @@ whether the migration worked. In this example the event `PrivacyAdded` is removed and the event `OldVisited` is replaced by `NewVisited`: ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware; -use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; -use Patchlevel\EventSourcing\Pipeline\Middleware\ReplaceEventMiddleware; -use Patchlevel\EventSourcing\Pipeline\Pipeline; -use Patchlevel\EventSourcing\Pipeline\Source\StoreSource; -use Patchlevel\EventSourcing\Pipeline\Target\StoreTarget; +use Patchlevel\EventSourcing\Message\Middleware\ExcludeEventMiddleware;use Patchlevel\EventSourcing\Message\Middleware\RecalculatePlayheadMiddleware;use Patchlevel\EventSourcing\Message\Middleware\ReplaceEventMiddleware;use Patchlevel\EventSourcing\Pipeline\Pipeline;use Patchlevel\EventSourcing\Pipeline\Source\StoreSource;use Patchlevel\EventSourcing\Pipeline\Target\StoreTarget; $pipeline = new Pipeline( new StoreSource($oldStore), @@ -211,7 +206,7 @@ Middelwares can be used to manipulate, delete or expand messages or events durin With this middleware you can exclude certain events. ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\ExcludeEventMiddleware; $middleware = new ExcludeEventMiddleware([EmailChanged::class]); ``` @@ -226,7 +221,7 @@ $middleware = new ExcludeEventMiddleware([EmailChanged::class]); With this middleware you can only allow certain events. ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\IncludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\IncludeEventMiddleware; $middleware = new IncludeEventMiddleware([ProfileCreated::class]); ``` @@ -242,8 +237,7 @@ you can also write your own filter. This middleware expects a callback that returns either true to allow events or false to not allow them. ```php -use Patchlevel\EventSourcing\Aggregate\AggregateChanged; -use Patchlevel\EventSourcing\Pipeline\Middleware\FilterEventMiddleware; +use Patchlevel\EventSourcing\Aggregate\AggregateChanged;use Patchlevel\EventSourcing\Message\Middleware\FilterEventMiddleware; $middleware = new FilterEventMiddleware(function (AggregateChanged $event) { if (!$event instanceof ProfileCreated) { @@ -263,7 +257,7 @@ $middleware = new FilterEventMiddleware(function (AggregateChanged $event) { With this middleware you can exclude archived events. ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\ExcludeArchivedEventMiddleware; $middleware = new ExcludeArchivedEventMiddleware(); ``` @@ -277,7 +271,7 @@ $middleware = new ExcludeArchivedEventMiddleware(); With this middleware you can only allow archived events. ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\OnlyArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\OnlyArchivedEventMiddleware; $middleware = new OnlyArchivedEventMiddleware(); ``` @@ -293,7 +287,7 @@ The first parameter you have to define is the event class that you want to repla And as a second parameter a callback, that the old event awaits and a new event returns. ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\ReplaceEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\ReplaceEventMiddleware; $middleware = new ReplaceEventMiddleware(OldVisited::class, static function (OldVisited $oldVisited) { return new NewVisited($oldVisited->profileId()); @@ -326,7 +320,7 @@ The playhead must always be in ascending order so that the data is valid. Some middleware can break this order and the middleware `RecalculatePlayheadMiddleware` can fix this problem. ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\RecalculatePlayheadMiddleware; $middleware = new RecalculatePlayheadMiddleware(); ``` @@ -340,9 +334,7 @@ $middleware = new RecalculatePlayheadMiddleware(); If you want to group your middleware, you can use one or more `ChainMiddleware`. ```php -use Patchlevel\EventSourcing\Pipeline\Middleware\ChainMiddleware; -use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware; -use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\ChainMiddleware;use Patchlevel\EventSourcing\Message\Middleware\ExcludeEventMiddleware;use Patchlevel\EventSourcing\Message\Middleware\RecalculatePlayheadMiddleware; $middleware = new ChainMiddleware([ new ExcludeEventMiddleware([EmailChanged::class]), @@ -366,8 +358,7 @@ Now we have a `ProfileRegistered` and a `ProfileActivated` event, which should replace the `ProfileCreated` event. ```php -use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\Middleware; +use Patchlevel\EventSourcing\Message\Message;use Patchlevel\EventSourcing\Message\Middleware\Middleware; final class SplitProfileCreatedMiddleware implements Middleware { diff --git a/src/Pipeline/Middleware/ChainMiddleware.php b/src/Message/Middleware/ChainMiddleware.php similarity index 94% rename from src/Pipeline/Middleware/ChainMiddleware.php rename to src/Message/Middleware/ChainMiddleware.php index eb449de1f..df97cbe96 100644 --- a/src/Pipeline/Middleware/ChainMiddleware.php +++ b/src/Message/Middleware/ChainMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/ExcludeArchivedEventMiddleware.php b/src/Message/Middleware/ExcludeArchivedEventMiddleware.php similarity index 91% rename from src/Pipeline/Middleware/ExcludeArchivedEventMiddleware.php rename to src/Message/Middleware/ExcludeArchivedEventMiddleware.php index 79152e642..1a9580ebb 100644 --- a/src/Pipeline/Middleware/ExcludeArchivedEventMiddleware.php +++ b/src/Message/Middleware/ExcludeArchivedEventMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\HeaderNotFound; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/ExcludeEventMiddleware.php b/src/Message/Middleware/ExcludeEventMiddleware.php similarity index 90% rename from src/Pipeline/Middleware/ExcludeEventMiddleware.php rename to src/Message/Middleware/ExcludeEventMiddleware.php index 0fcb96376..7e6c889b9 100644 --- a/src/Pipeline/Middleware/ExcludeEventMiddleware.php +++ b/src/Message/Middleware/ExcludeEventMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/FilterEventMiddleware.php b/src/Message/Middleware/FilterEventMiddleware.php similarity index 91% rename from src/Pipeline/Middleware/FilterEventMiddleware.php rename to src/Message/Middleware/FilterEventMiddleware.php index 9aeaefb55..84caf259b 100644 --- a/src/Pipeline/Middleware/FilterEventMiddleware.php +++ b/src/Message/Middleware/FilterEventMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/IncludeEventMiddleware.php b/src/Message/Middleware/IncludeEventMiddleware.php similarity index 90% rename from src/Pipeline/Middleware/IncludeEventMiddleware.php rename to src/Message/Middleware/IncludeEventMiddleware.php index 7b3262423..d30d23622 100644 --- a/src/Pipeline/Middleware/IncludeEventMiddleware.php +++ b/src/Message/Middleware/IncludeEventMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/Middleware.php b/src/Message/Middleware/Middleware.php similarity index 77% rename from src/Pipeline/Middleware/Middleware.php rename to src/Message/Middleware/Middleware.php index 490f19514..89031ec8e 100644 --- a/src/Pipeline/Middleware/Middleware.php +++ b/src/Message/Middleware/Middleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/OnlyArchivedEventMiddleware.php b/src/Message/Middleware/OnlyArchivedEventMiddleware.php similarity index 91% rename from src/Pipeline/Middleware/OnlyArchivedEventMiddleware.php rename to src/Message/Middleware/OnlyArchivedEventMiddleware.php index 02be897a8..ffa60b941 100644 --- a/src/Pipeline/Middleware/OnlyArchivedEventMiddleware.php +++ b/src/Message/Middleware/OnlyArchivedEventMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\HeaderNotFound; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/RecalculatePlayheadMiddleware.php b/src/Message/Middleware/RecalculatePlayheadMiddleware.php similarity index 96% rename from src/Pipeline/Middleware/RecalculatePlayheadMiddleware.php rename to src/Message/Middleware/RecalculatePlayheadMiddleware.php index 1df72ec19..865ba818f 100644 --- a/src/Pipeline/Middleware/RecalculatePlayheadMiddleware.php +++ b/src/Message/Middleware/RecalculatePlayheadMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/ReplaceEventMiddleware.php b/src/Message/Middleware/ReplaceEventMiddleware.php similarity index 93% rename from src/Pipeline/Middleware/ReplaceEventMiddleware.php rename to src/Message/Middleware/ReplaceEventMiddleware.php index 9dc92fdb5..2ba530d04 100644 --- a/src/Pipeline/Middleware/ReplaceEventMiddleware.php +++ b/src/Message/Middleware/ReplaceEventMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; diff --git a/src/Pipeline/Middleware/UntilEventMiddleware.php b/src/Message/Middleware/UntilEventMiddleware.php similarity index 91% rename from src/Pipeline/Middleware/UntilEventMiddleware.php rename to src/Message/Middleware/UntilEventMiddleware.php index 4eb35e49e..9964fe0ba 100644 --- a/src/Pipeline/Middleware/UntilEventMiddleware.php +++ b/src/Message/Middleware/UntilEventMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Message\Middleware; use DateTimeImmutable; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; diff --git a/src/Pipeline/Pipeline.php b/src/Pipeline/Pipeline.php deleted file mode 100644 index cecab3974..000000000 --- a/src/Pipeline/Pipeline.php +++ /dev/null @@ -1,44 +0,0 @@ - $middlewares */ - public function __construct( - private readonly Source $source, - private readonly Target $target, - array $middlewares = [], - ) { - $this->middlewares = new ChainMiddleware($middlewares); - } - - public function run(Closure|null $observer = null): void - { - foreach ($this->source->load() as $message) { - $result = ($this->middlewares)($message); - $this->target->save(...$result); - - if (!$observer) { - continue; - } - - $observer($message); - } - } - - public function count(): int - { - return $this->source->count(); - } -} diff --git a/src/Pipeline/Source/InMemorySource.php b/src/Pipeline/Source/InMemorySource.php deleted file mode 100644 index 2d96ef133..000000000 --- a/src/Pipeline/Source/InMemorySource.php +++ /dev/null @@ -1,35 +0,0 @@ - $messages */ - public function __construct( - private readonly iterable $messages, - ) { - } - - /** @return iterable */ - public function load(): iterable - { - yield from $this->messages; - } - - public function count(): int - { - if (is_array($this->messages)) { - return count($this->messages); - } - - return count(iterator_to_array($this->messages)); - } -} diff --git a/src/Pipeline/Source/Source.php b/src/Pipeline/Source/Source.php deleted file mode 100644 index 1067c96f4..000000000 --- a/src/Pipeline/Source/Source.php +++ /dev/null @@ -1,15 +0,0 @@ - */ - public function load(): iterable; - - public function count(): int; -} diff --git a/src/Pipeline/Source/StoreSource.php b/src/Pipeline/Source/StoreSource.php deleted file mode 100644 index 07cfdacd5..000000000 --- a/src/Pipeline/Source/StoreSource.php +++ /dev/null @@ -1,36 +0,0 @@ - */ - public function load(): Traversable - { - return $this->store->load($this->criteria()); - } - - public function count(): int - { - return $this->store->count($this->criteria()); - } - - private function criteria(): Criteria - { - return (new CriteriaBuilder())->fromIndex($this->fromIndex)->build(); - } -} diff --git a/src/Pipeline/Target/ConsumerTarget.php b/src/Pipeline/Target/ConsumerTarget.php deleted file mode 100644 index cef6de08d..000000000 --- a/src/Pipeline/Target/ConsumerTarget.php +++ /dev/null @@ -1,30 +0,0 @@ -consumer->consume($message); - } - } - - /** @param iterable $listeners */ - public static function create(iterable $listeners): self - { - return new self(DefaultConsumer::create($listeners)); - } -} diff --git a/src/Pipeline/Target/InMemoryTarget.php b/src/Pipeline/Target/InMemoryTarget.php deleted file mode 100644 index ef81c34f0..000000000 --- a/src/Pipeline/Target/InMemoryTarget.php +++ /dev/null @@ -1,26 +0,0 @@ - */ - private array $messages = []; - - public function save(Message ...$messages): void - { - foreach ($messages as $message) { - $this->messages[] = $message; - } - } - - /** @return list */ - public function messages(): array - { - return $this->messages; - } -} diff --git a/src/Pipeline/Target/StoreTarget.php b/src/Pipeline/Target/StoreTarget.php deleted file mode 100644 index 0d51ecc82..000000000 --- a/src/Pipeline/Target/StoreTarget.php +++ /dev/null @@ -1,21 +0,0 @@ -store->save(...$messages); - } -} diff --git a/src/Pipeline/Target/Target.php b/src/Pipeline/Target/Target.php deleted file mode 100644 index 0f7ec1d04..000000000 --- a/src/Pipeline/Target/Target.php +++ /dev/null @@ -1,12 +0,0 @@ -recordThat(new ProfileCreated($id)); - - return $self; - } - - public function visit(): void - { - $this->recordThat(new OldVisited($this->id)); - } - - public function privacy(): void - { - $this->recordThat(new PrivacyAdded($this->id)); - } - - public function isPrivate(): bool - { - return $this->privacy; - } - - public function count(): int - { - return $this->visited; - } - - #[Apply(ProfileCreated::class)] - protected function applyProfileCreated(ProfileCreated $event): void - { - $this->id = $event->profileId; - $this->privacy = false; - $this->visited = 0; - } - - #[Apply(OldVisited::class)] - protected function applyOldVisited(OldVisited $event): void - { - $this->visited++; - } - - #[Apply(NewVisited::class)] - protected function applyNewVisited(NewVisited $event): void - { - $this->visited--; - } - - #[Apply(PrivacyAdded::class)] - protected function applyPrivacyAdded(PrivacyAdded $event): void - { - $this->privacy = true; - } -} diff --git a/tests/Integration/Pipeline/EventNormalizer/ProfileIdNormalizer.php b/tests/Integration/Pipeline/EventNormalizer/ProfileIdNormalizer.php deleted file mode 100644 index beee664bc..000000000 --- a/tests/Integration/Pipeline/EventNormalizer/ProfileIdNormalizer.php +++ /dev/null @@ -1,38 +0,0 @@ -toString(); - } - - public function denormalize(mixed $value): ProfileId|null - { - if ($value === null) { - return null; - } - - if (!is_string($value)) { - throw new InvalidArgumentException(); - } - - return ProfileId::fromString($value); - } -} diff --git a/tests/Integration/Pipeline/Events/NewVisited.php b/tests/Integration/Pipeline/Events/NewVisited.php deleted file mode 100644 index 0a4c4faad..000000000 --- a/tests/Integration/Pipeline/Events/NewVisited.php +++ /dev/null @@ -1,19 +0,0 @@ -connectionOld = DbalManager::createConnection(); - $this->connectionNew = DbalManager::createConnection('eventstore_new'); - } - - public function tearDown(): void - { - $this->connectionOld->close(); - $this->connectionNew->close(); - } - - public function testSuccessful(): void - { - $eventSerializer = DefaultEventSerializer::createFromPaths([__DIR__ . '/Events']); - $headersSerializer = DefaultHeadersSerializer::createFromPaths([ - __DIR__ . '/../../../src', - __DIR__, - ]); - - $oldStore = new DoctrineDbalStore( - $this->connectionOld, - $eventSerializer, - $headersSerializer, - 'eventstore', - ); - - $oldSchemaDirector = new DoctrineSchemaDirector( - $this->connectionOld, - $oldStore, - ); - - $oldSchemaDirector->create(); - - $newStore = new DoctrineDbalStore( - $this->connectionNew, - $eventSerializer, - $headersSerializer, - 'eventstore', - ); - - $newSchemaDirector = new DoctrineSchemaDirector( - $this->connectionNew, - $newStore, - ); - - $newSchemaDirector->create(); - - $oldRepository = new DefaultRepository($oldStore, DefaultEventBus::create(), Profile::metadata()); - $newRepository = new DefaultRepository($newStore, DefaultEventBus::create(), Profile::metadata()); - - $profileId = ProfileId::fromString('1'); - $profile = Profile::create($profileId); - $profile->visit(); - $profile->privacy(); - $profile->visit(); - - $oldRepository->save($profile); - self::assertSame(4, $oldStore->count()); - - self::assertEquals($profileId, $profile->aggregateRootId()); - self::assertSame(4, $profile->playhead()); - self::assertSame(true, $profile->isPrivate()); - self::assertSame(2, $profile->count()); - - $pipeline = new Pipeline( - new StoreSource($oldStore), - new StoreTarget($newStore), - [ - new ExcludeEventMiddleware([PrivacyAdded::class]), - new ReplaceEventMiddleware(OldVisited::class, static function (OldVisited $oldVisited) { - return new NewVisited($oldVisited->profileId); - }), - new RecalculatePlayheadMiddleware(), - ], - ); - - self::assertSame(4, $pipeline->count()); - $pipeline->run(); - - $newProfile = $newRepository->load($profileId); - - self::assertInstanceOf(Profile::class, $newProfile); - self::assertEquals($profileId, $newProfile->aggregateRootId()); - self::assertSame(3, $newProfile->playhead()); - self::assertSame(false, $newProfile->isPrivate()); - self::assertSame(-2, $newProfile->count()); - } -} diff --git a/tests/Integration/Pipeline/ProfileId.php b/tests/Integration/Pipeline/ProfileId.php deleted file mode 100644 index 236d4b3a2..000000000 --- a/tests/Integration/Pipeline/ProfileId.php +++ /dev/null @@ -1,25 +0,0 @@ -id; - } -} diff --git a/tests/Unit/Pipeline/Middleware/ChainMiddlewareTest.php b/tests/Unit/Message/Middleware/ChainMiddlewareTest.php similarity index 79% rename from tests/Unit/Pipeline/Middleware/ChainMiddlewareTest.php rename to tests/Unit/Message/Middleware/ChainMiddlewareTest.php index 8f6b0ea36..f6fd954de 100644 --- a/tests/Unit/Pipeline/Middleware/ChainMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/ChainMiddlewareTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\ChainMiddleware; -use Patchlevel\EventSourcing\Pipeline\Middleware\Middleware; +use Patchlevel\EventSourcing\Message\Middleware\ChainMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\Middleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\ChainMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\ChainMiddleware */ final class ChainMiddlewareTest extends TestCase { use ProphecyTrait; diff --git a/tests/Unit/Pipeline/Middleware/ExcludeArchivedEventMiddlewareTest.php b/tests/Unit/Message/Middleware/ExcludeArchivedEventMiddlewareTest.php similarity index 87% rename from tests/Unit/Pipeline/Middleware/ExcludeArchivedEventMiddlewareTest.php rename to tests/Unit/Message/Middleware/ExcludeArchivedEventMiddlewareTest.php index 4d3849dcb..cf5ca89a6 100644 --- a/tests/Unit/Pipeline/Middleware/ExcludeArchivedEventMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/ExcludeArchivedEventMiddlewareTest.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\ExcludeArchivedEventMiddleware; use Patchlevel\EventSourcing\Store\ArchivedHeader; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeArchivedEventMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\ExcludeArchivedEventMiddleware */ final class ExcludeArchivedEventMiddlewareTest extends TestCase { public function testExcludedEvent(): void diff --git a/tests/Unit/Pipeline/Middleware/ExcludeEventMiddlewareTest.php b/tests/Unit/Message/Middleware/ExcludeEventMiddlewareTest.php similarity index 84% rename from tests/Unit/Pipeline/Middleware/ExcludeEventMiddlewareTest.php rename to tests/Unit/Message/Middleware/ExcludeEventMiddlewareTest.php index d305f1bd3..f8d00c1d8 100644 --- a/tests/Unit/Pipeline/Middleware/ExcludeEventMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/ExcludeEventMiddlewareTest.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\ExcludeEventMiddleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\ExcludeEventMiddleware */ final class ExcludeEventMiddlewareTest extends TestCase { public function testDeleteEvent(): void diff --git a/tests/Unit/Pipeline/Middleware/FilterEventMiddlewareTest.php b/tests/Unit/Message/Middleware/FilterEventMiddlewareTest.php similarity index 85% rename from tests/Unit/Pipeline/Middleware/FilterEventMiddlewareTest.php rename to tests/Unit/Message/Middleware/FilterEventMiddlewareTest.php index 5ddc0f7e1..f8c3903f4 100644 --- a/tests/Unit/Pipeline/Middleware/FilterEventMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/FilterEventMiddlewareTest.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\FilterEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\FilterEventMiddleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\FilterEventMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\FilterEventMiddleware */ final class FilterEventMiddlewareTest extends TestCase { public function testPositive(): void diff --git a/tests/Unit/Pipeline/Middleware/IncludeEventMiddlewareTest.php b/tests/Unit/Message/Middleware/IncludeEventMiddlewareTest.php similarity index 84% rename from tests/Unit/Pipeline/Middleware/IncludeEventMiddlewareTest.php rename to tests/Unit/Message/Middleware/IncludeEventMiddlewareTest.php index 2ba7171e3..6489307e5 100644 --- a/tests/Unit/Pipeline/Middleware/IncludeEventMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/IncludeEventMiddlewareTest.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\IncludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\IncludeEventMiddleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\IncludeEventMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\IncludeEventMiddleware */ final class IncludeEventMiddlewareTest extends TestCase { public function testFilterEvent(): void diff --git a/tests/Unit/Pipeline/Middleware/OnlyArchivedEventMiddlewareTest.php b/tests/Unit/Message/Middleware/OnlyArchivedEventMiddlewareTest.php similarity index 87% rename from tests/Unit/Pipeline/Middleware/OnlyArchivedEventMiddlewareTest.php rename to tests/Unit/Message/Middleware/OnlyArchivedEventMiddlewareTest.php index b42910da5..9d105c262 100644 --- a/tests/Unit/Pipeline/Middleware/OnlyArchivedEventMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/OnlyArchivedEventMiddlewareTest.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\OnlyArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\OnlyArchivedEventMiddleware; use Patchlevel\EventSourcing\Store\ArchivedHeader; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\OnlyArchivedEventMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\OnlyArchivedEventMiddleware */ final class OnlyArchivedEventMiddlewareTest extends TestCase { public function testExcludedEvent(): void diff --git a/tests/Unit/Pipeline/Middleware/RecalculatePlayheadMiddlewareTest.php b/tests/Unit/Message/Middleware/RecalculatePlayheadMiddlewareTest.php similarity index 94% rename from tests/Unit/Pipeline/Middleware/RecalculatePlayheadMiddlewareTest.php rename to tests/Unit/Message/Middleware/RecalculatePlayheadMiddlewareTest.php index f152e804a..b1eca434e 100644 --- a/tests/Unit/Pipeline/Middleware/RecalculatePlayheadMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/RecalculatePlayheadMiddlewareTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use DateTimeImmutable; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\RecalculatePlayheadMiddleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\RecalculatePlayheadMiddleware */ final class RecalculatePlayheadMiddlewareTest extends TestCase { public function testRecalculatePlayhead(): void diff --git a/tests/Unit/Pipeline/Middleware/ReplaceEventMiddlewareTest.php b/tests/Unit/Message/Middleware/ReplaceEventMiddlewareTest.php similarity index 89% rename from tests/Unit/Pipeline/Middleware/ReplaceEventMiddlewareTest.php rename to tests/Unit/Message/Middleware/ReplaceEventMiddlewareTest.php index d7098a9f0..12cb8b579 100644 --- a/tests/Unit/Pipeline/Middleware/ReplaceEventMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/ReplaceEventMiddlewareTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\ReplaceEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\ReplaceEventMiddleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\MessagePublished; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; @@ -13,7 +13,7 @@ use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\ReplaceEventMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\ReplaceEventMiddleware */ final class ReplaceEventMiddlewareTest extends TestCase { public function testReplace(): void diff --git a/tests/Unit/Pipeline/Middleware/UntilEventMiddlewareTest.php b/tests/Unit/Message/Middleware/UntilEventMiddlewareTest.php similarity index 87% rename from tests/Unit/Pipeline/Middleware/UntilEventMiddlewareTest.php rename to tests/Unit/Message/Middleware/UntilEventMiddlewareTest.php index 891d22e43..3cae0b31a 100644 --- a/tests/Unit/Pipeline/Middleware/UntilEventMiddlewareTest.php +++ b/tests/Unit/Message/Middleware/UntilEventMiddlewareTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; use DateTimeImmutable; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Pipeline\Middleware\UntilEventMiddleware; +use Patchlevel\EventSourcing\Message\Middleware\UntilEventMiddleware; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\UntilEventMiddleware */ +/** @covers \Patchlevel\EventSourcing\Message\Middleware\UntilEventMiddleware */ final class UntilEventMiddlewareTest extends TestCase { public function testPositive(): void diff --git a/tests/Unit/Pipeline/PipelineTest.php b/tests/Unit/Pipeline/PipelineTest.php deleted file mode 100644 index 38dde9de0..000000000 --- a/tests/Unit/Pipeline/PipelineTest.php +++ /dev/null @@ -1,137 +0,0 @@ -messages(); - - $source = new InMemorySource($messages); - $target = new InMemoryTarget(); - $pipeline = new Pipeline($source, $target); - - self::assertSame(5, $pipeline->count()); - - $pipeline->run(); - - self::assertSame($messages, $target->messages()); - } - - public function testPipelineWithObserver(): void - { - $messages = $this->messages(); - - $source = new InMemorySource($messages); - $target = new InMemoryTarget(); - $pipeline = new Pipeline($source, $target); - - self::assertSame(5, $pipeline->count()); - - $observer = new class { - public bool $called = false; - - public function __invoke(Message $message): void - { - $this->called = true; - } - }; - - $pipeline->run($observer->__invoke(...)); - - self::assertSame($messages, $target->messages()); - self::assertTrue($observer->called); - } - - public function testPipelineWithMiddleware(): void - { - $messages = $this->messages(); - - $source = new InMemorySource($messages); - $target = new InMemoryTarget(); - $pipeline = new Pipeline( - $source, - $target, - [ - new ExcludeEventMiddleware([ProfileCreated::class]), - new RecalculatePlayheadMiddleware(), - ], - ); - - self::assertSame(5, $pipeline->count()); - - $pipeline->run(); - - $resultMessages = $target->messages(); - - self::assertCount(3, $resultMessages); - - self::assertInstanceOf(ProfileVisited::class, $resultMessages[0]->event()); - self::assertSame('1', $resultMessages[0]->header(AggregateHeader::class)->aggregateId); - self::assertSame(1, $resultMessages[0]->header(AggregateHeader::class)->playhead); - - self::assertInstanceOf(ProfileVisited::class, $resultMessages[1]->event()); - self::assertSame('1', $resultMessages[1]->header(AggregateHeader::class)->aggregateId); - self::assertSame(2, $resultMessages[1]->header(AggregateHeader::class)->playhead); - - self::assertInstanceOf(ProfileVisited::class, $resultMessages[2]->event()); - self::assertSame('2', $resultMessages[2]->header(AggregateHeader::class)->aggregateId); - self::assertSame(1, $resultMessages[2]->header(AggregateHeader::class)->playhead); - } - - /** @return list */ - private function messages(): array - { - return [ - Message::create( - new ProfileCreated( - ProfileId::fromString('1'), - Email::fromString('hallo@patchlevel.de'), - ), - )->withHeader(new AggregateHeader('profile', '1', 1, new DateTimeImmutable())), - - Message::create( - new ProfileVisited( - ProfileId::fromString('1'), - ), - )->withHeader(new AggregateHeader('profile', '1', 2, new DateTimeImmutable())), - - Message::create( - new ProfileVisited( - ProfileId::fromString('1'), - ), - )->withHeader(new AggregateHeader('profile', '1', 3, new DateTimeImmutable())), - - Message::create( - new ProfileCreated( - ProfileId::fromString('2'), - Email::fromString('hallo@patchlevel.de'), - ), - )->withHeader(new AggregateHeader('profile', '2', 1, new DateTimeImmutable())), - - Message::create( - new ProfileVisited( - ProfileId::fromString('2'), - ), - )->withHeader(new AggregateHeader('profile', '2', 2, new DateTimeImmutable())), - ]; - } -} diff --git a/tests/Unit/Pipeline/Source/InMemorySourceTest.php b/tests/Unit/Pipeline/Source/InMemorySourceTest.php deleted file mode 100644 index 09592915b..000000000 --- a/tests/Unit/Pipeline/Source/InMemorySourceTest.php +++ /dev/null @@ -1,56 +0,0 @@ -load(); - - self::assertSame($message, $generator->current()); - - $generator->next(); - - self::assertSame(null, $generator->current()); - } - - public function testCount(): void - { - $message = new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('foo@test.com')), - ); - - $source = new InMemorySource([$message]); - - self::assertSame(1, $source->count()); - } - - public function testCountWithIterator(): void - { - $message = new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('foo@test.com')), - ); - - $source = new InMemorySource(new ArrayIterator([$message])); - - self::assertSame(1, $source->count()); - } -} diff --git a/tests/Unit/Pipeline/Source/StoreSourceTest.php b/tests/Unit/Pipeline/Source/StoreSourceTest.php deleted file mode 100644 index 0e3980f24..000000000 --- a/tests/Unit/Pipeline/Source/StoreSourceTest.php +++ /dev/null @@ -1,80 +0,0 @@ -prophesize(Store::class); - $pipelineStore->load($this->criteria())->willReturn($stream); - - $source = new StoreSource($pipelineStore->reveal()); - - self::assertSame($stream, $source->load()); - } - - public function testLoadWithFromIndex(): void - { - $message = new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('foo@test.com')), - ); - - $stream = new ArrayStream([$message]); - - $pipelineStore = $this->prophesize(Store::class); - $pipelineStore->load($this->criteria(1))->willReturn($stream); - - $source = new StoreSource($pipelineStore->reveal(), 1); - - self::assertSame($stream, $source->load()); - } - - public function testCount(): void - { - $pipelineStore = $this->prophesize(Store::class); - $pipelineStore->count($this->criteria())->willReturn(1); - - $source = new StoreSource($pipelineStore->reveal()); - - self::assertSame(1, $source->count()); - } - - public function testCountWithFromIndex(): void - { - $pipelineStore = $this->prophesize(Store::class); - $pipelineStore->count($this->criteria(1))->willReturn(0); - - $source = new StoreSource($pipelineStore->reveal(), 1); - - self::assertSame(0, $source->count()); - } - - private function criteria(int $fromIndex = 0): Criteria - { - return (new CriteriaBuilder())->fromIndex($fromIndex)->build(); - } -} diff --git a/tests/Unit/Pipeline/Target/ConsumerTargetTest.php b/tests/Unit/Pipeline/Target/ConsumerTargetTest.php deleted file mode 100644 index d495d5806..000000000 --- a/tests/Unit/Pipeline/Target/ConsumerTargetTest.php +++ /dev/null @@ -1,56 +0,0 @@ -prophesize(Consumer::class); - $consumer->consume($message)->shouldBeCalledOnce(); - - $consumerTarget = new ConsumerTarget($consumer->reveal()); - $consumerTarget->save($message); - } - - public function testCreate(): void - { - $message = new Message( - new ProfileCreated(ProfileId::fromString('1'), Email::fromString('foo@test.com')), - ); - - $listener = new class { - public int $count = 0; - - #[Subscribe(Subscribe::ALL)] - public function consumeAll(Message $message): void - { - $this->count++; - } - }; - - $consumerTarget = ConsumerTarget::create([$listener]); - $consumerTarget->save($message); - - self::assertSame(1, $listener->count); - } -} diff --git a/tests/Unit/Pipeline/Target/InMemoryTargetTest.php b/tests/Unit/Pipeline/Target/InMemoryTargetTest.php deleted file mode 100644 index b18bfd0d4..000000000 --- a/tests/Unit/Pipeline/Target/InMemoryTargetTest.php +++ /dev/null @@ -1,30 +0,0 @@ -save($message); - - $messages = $inMemoryTarget->messages(); - - self::assertSame([$message], $messages); - } -} diff --git a/tests/Unit/Pipeline/Target/StoreTargetTest.php b/tests/Unit/Pipeline/Target/StoreTargetTest.php deleted file mode 100644 index 187ac642a..000000000 --- a/tests/Unit/Pipeline/Target/StoreTargetTest.php +++ /dev/null @@ -1,34 +0,0 @@ -prophesize(Store::class); - $pipelineStore->save($message)->shouldBeCalled(); - - $storeTarget = new StoreTarget($pipelineStore->reveal()); - - $storeTarget->save($message); - } -}