diff --git a/docs/pages/pipeline.md b/docs/pages/pipeline.md index 31600b796..2a58c68fc 100644 --- a/docs/pages/pipeline.md +++ b/docs/pages/pipeline.md @@ -10,17 +10,22 @@ whether the migration worked. In this example the event `PrivacyAdded` is removed and the event `OldVisited` is replaced by `NewVisited`: ```php -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; +use Patchlevel\EventSourcing\Message\Translator\ExcludeEventTranslator; +use Patchlevel\EventSourcing\Message\Translator\RecalculatePlayheadTranslator; +use Patchlevel\EventSourcing\Message\Translator\ReplaceEventTranslator; +use Patchlevel\EventSourcing\Pipeline\Pipeline; +use Patchlevel\EventSourcing\Pipeline\Source\StoreSource; +use Patchlevel\EventSourcing\Pipeline\Target\StoreTarget; $pipeline = new Pipeline( new StoreSource($oldStore), new StoreTarget($newStore), [ - new ExcludeEventMiddleware([PrivacyAdded::class]), - new ReplaceEventMiddleware(OldVisited::class, static function (OldVisited $oldVisited) { + new ExcludeEventTranslator([PrivacyAdded::class]), + new ReplaceEventTranslator(OldVisited::class, static function (OldVisited $oldVisited) { return new NewVisited($oldVisited->profileId()); }), - new RecalculatePlayheadMiddleware(), + new RecalculatePlayheadTranslator(), ], ); ``` @@ -192,9 +197,9 @@ 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\Message\Middleware\ExcludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\ExcludeEventTranslator; -$middleware = new ExcludeEventMiddleware([EmailChanged::class]); +$middleware = new ExcludeEventTranslator([EmailChanged::class]); ``` !!! warning @@ -205,9 +210,9 @@ $middleware = new ExcludeEventMiddleware([EmailChanged::class]); With this middleware you can only allow certain events. ```php -use Patchlevel\EventSourcing\Message\Middleware\IncludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\IncludeEventTranslator; -$middleware = new IncludeEventMiddleware([ProfileCreated::class]); +$middleware = new IncludeEventTranslator([ProfileCreated::class]); ``` !!! warning @@ -220,9 +225,10 @@ 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\Message\Middleware\FilterEventMiddleware; +use Patchlevel\EventSourcing\Aggregate\AggregateChanged; +use Patchlevel\EventSourcing\Message\Translator\FilterEventTranslator; -$middleware = new FilterEventMiddleware(static function (AggregateChanged $event) { +$middleware = new FilterEventTranslator(static function (AggregateChanged $event) { if (!$event instanceof ProfileCreated) { return true; } @@ -239,9 +245,9 @@ $middleware = new FilterEventMiddleware(static function (AggregateChanged $event With this middleware you can exclude archived events. ```php -use Patchlevel\EventSourcing\Message\Middleware\ExcludeArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\ExcludeArchivedEventTranslator; -$middleware = new ExcludeArchivedEventMiddleware(); +$middleware = new ExcludeArchivedEventTranslator(); ``` !!! warning @@ -252,9 +258,9 @@ $middleware = new ExcludeArchivedEventMiddleware(); With this middleware you can only allow archived events. ```php -use Patchlevel\EventSourcing\Message\Middleware\OnlyArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\OnlyArchivedEventTranslator; -$middleware = new OnlyArchivedEventMiddleware(); +$middleware = new OnlyArchivedEventTranslator(); ``` !!! warning @@ -267,9 +273,9 @@ 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\Message\Middleware\ReplaceEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\ReplaceEventTranslator; -$middleware = new ReplaceEventMiddleware(OldVisited::class, static function (OldVisited $oldVisited) { +$middleware = new ReplaceEventTranslator(OldVisited::class, static function (OldVisited $oldVisited) { return new NewVisited($oldVisited->profileId()); }); ``` @@ -296,9 +302,9 @@ 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\Message\Middleware\RecalculatePlayheadMiddleware; +use Patchlevel\EventSourcing\Message\Translator\RecalculatePlayheadTranslator; -$middleware = new RecalculatePlayheadMiddleware(); +$middleware = new RecalculatePlayheadTranslator(); ``` !!! note @@ -309,11 +315,13 @@ $middleware = new RecalculatePlayheadMiddleware(); If you want to group your middleware, you can use one or more `ChainMiddleware`. ```php -use Patchlevel\EventSourcing\Message\Middleware\ChainMiddleware;use Patchlevel\EventSourcing\Message\Middleware\ExcludeEventMiddleware;use Patchlevel\EventSourcing\Message\Middleware\RecalculatePlayheadMiddleware; +use Patchlevel\EventSourcing\Message\Translator\ChainTranslator; +use Patchlevel\EventSourcing\Message\Translator\ExcludeEventTranslator; +use Patchlevel\EventSourcing\Message\Translator\RecalculatePlayheadTranslator; -$middleware = new ChainMiddleware([ - new ExcludeEventMiddleware([EmailChanged::class]), - new RecalculatePlayheadMiddleware(), +$middleware = new ChainTranslator([ + new ExcludeEventTranslator([EmailChanged::class]), + new RecalculatePlayheadTranslator(), ]); ``` ### Custom middleware @@ -332,9 +340,10 @@ Now we have a `ProfileRegistered` and a `ProfileActivated` event, which should replace the `ProfileCreated` event. ```php -use Patchlevel\EventSourcing\Message\Message;use Patchlevel\EventSourcing\Message\Middleware\Middleware; +use Patchlevel\EventSourcing\Message\Message; +use Patchlevel\EventSourcing\Message\Translator\Translator; -final class SplitProfileCreatedMiddleware implements Middleware +final class SplitProfileCreatedMiddleware implements Translator { public function __invoke(Message $message): array { diff --git a/src/Message/Middleware/ChainMiddleware.php b/src/Message/Translator/ChainTranslator.php similarity index 53% rename from src/Message/Middleware/ChainMiddleware.php rename to src/Message/Translator/ChainTranslator.php index df97cbe96..708bdb3b4 100644 --- a/src/Message/Middleware/ChainMiddleware.php +++ b/src/Message/Translator/ChainTranslator.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\Message; use function array_values; -final class ChainMiddleware implements Middleware +final class ChainTranslator implements Translator { - /** @param iterable $middlewares */ + /** @param iterable $translators */ public function __construct( - private readonly iterable $middlewares, + private readonly iterable $translators, ) { } @@ -21,8 +21,8 @@ public function __invoke(Message $message): array { $messages = [$message]; - foreach ($this->middlewares as $middleware) { - $messages = $this->processMiddleware($middleware, $messages); + foreach ($this->translators as $middleware) { + $messages = $this->process($middleware, $messages); } return $messages; @@ -33,12 +33,12 @@ public function __invoke(Message $message): array * * @return list */ - private function processMiddleware(Middleware $middleware, array $messages): array + private function process(Translator $translator, array $messages): array { $result = []; foreach ($messages as $message) { - $result += $middleware($message); + $result += $translator($message); } return array_values($result); diff --git a/src/Message/Middleware/ExcludeArchivedEventMiddleware.php b/src/Message/Translator/ExcludeArchivedEventTranslator.php similarity index 81% rename from src/Message/Middleware/ExcludeArchivedEventMiddleware.php rename to src/Message/Translator/ExcludeArchivedEventTranslator.php index 1a9580ebb..9bc904dae 100644 --- a/src/Message/Middleware/ExcludeArchivedEventMiddleware.php +++ b/src/Message/Translator/ExcludeArchivedEventTranslator.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\HeaderNotFound; use Patchlevel\EventSourcing\Message\Message; use Patchlevel\EventSourcing\Store\ArchivedHeader; -final class ExcludeArchivedEventMiddleware implements Middleware +final class ExcludeArchivedEventTranslator implements Translator { /** @return list */ public function __invoke(Message $message): array diff --git a/src/Message/Middleware/ExcludeEventMiddleware.php b/src/Message/Translator/ExcludeEventTranslator.php similarity index 81% rename from src/Message/Middleware/ExcludeEventMiddleware.php rename to src/Message/Translator/ExcludeEventTranslator.php index 7e6c889b9..f4a26f632 100644 --- a/src/Message/Middleware/ExcludeEventMiddleware.php +++ b/src/Message/Translator/ExcludeEventTranslator.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -final class ExcludeEventMiddleware implements Middleware +final class ExcludeEventTranslator implements Translator { /** @param list $classes */ public function __construct( diff --git a/src/Message/Middleware/FilterEventMiddleware.php b/src/Message/Translator/FilterEventTranslator.php similarity index 83% rename from src/Message/Middleware/FilterEventMiddleware.php rename to src/Message/Translator/FilterEventTranslator.php index 84caf259b..b8f3c5b78 100644 --- a/src/Message/Middleware/FilterEventMiddleware.php +++ b/src/Message/Translator/FilterEventTranslator.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -final class FilterEventMiddleware implements Middleware +final class FilterEventTranslator implements Translator { /** @var callable(object $event):bool */ private $callable; diff --git a/src/Message/Middleware/IncludeEventMiddleware.php b/src/Message/Translator/IncludeEventTranslator.php similarity index 81% rename from src/Message/Middleware/IncludeEventMiddleware.php rename to src/Message/Translator/IncludeEventTranslator.php index d30d23622..ae2a412f5 100644 --- a/src/Message/Middleware/IncludeEventMiddleware.php +++ b/src/Message/Translator/IncludeEventTranslator.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -final class IncludeEventMiddleware implements Middleware +final class IncludeEventTranslator implements Translator { /** @param list $classes */ public function __construct( diff --git a/src/Message/Middleware/OnlyArchivedEventMiddleware.php b/src/Message/Translator/OnlyArchivedEventTranslator.php similarity index 82% rename from src/Message/Middleware/OnlyArchivedEventMiddleware.php rename to src/Message/Translator/OnlyArchivedEventTranslator.php index ffa60b941..b1db0ed89 100644 --- a/src/Message/Middleware/OnlyArchivedEventMiddleware.php +++ b/src/Message/Translator/OnlyArchivedEventTranslator.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\HeaderNotFound; use Patchlevel\EventSourcing\Message\Message; use Patchlevel\EventSourcing\Store\ArchivedHeader; -final class OnlyArchivedEventMiddleware implements Middleware +final class OnlyArchivedEventTranslator implements Translator { /** @return list */ public function __invoke(Message $message): array diff --git a/src/Message/Middleware/RecalculatePlayheadMiddleware.php b/src/Message/Translator/RecalculatePlayheadTranslator.php similarity index 92% rename from src/Message/Middleware/RecalculatePlayheadMiddleware.php rename to src/Message/Translator/RecalculatePlayheadTranslator.php index 865ba818f..1efc95adf 100644 --- a/src/Message/Middleware/RecalculatePlayheadMiddleware.php +++ b/src/Message/Translator/RecalculatePlayheadTranslator.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; use Patchlevel\EventSourcing\Message\Message; use function array_key_exists; -final class RecalculatePlayheadMiddleware implements Middleware +final class RecalculatePlayheadTranslator implements Translator { /** @var array> */ private array $index = []; diff --git a/src/Message/Middleware/ReplaceEventMiddleware.php b/src/Message/Translator/ReplaceEventTranslator.php similarity index 87% rename from src/Message/Middleware/ReplaceEventMiddleware.php rename to src/Message/Translator/ReplaceEventTranslator.php index 2ba530d04..3e13fa416 100644 --- a/src/Message/Middleware/ReplaceEventMiddleware.php +++ b/src/Message/Translator/ReplaceEventTranslator.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\Message; /** @template T of object */ -final class ReplaceEventMiddleware implements Middleware +final class ReplaceEventTranslator implements Translator { /** @var callable(T $event):object */ private $callable; diff --git a/src/Message/Middleware/Middleware.php b/src/Message/Translator/Translator.php similarity index 69% rename from src/Message/Middleware/Middleware.php rename to src/Message/Translator/Translator.php index 89031ec8e..66fe20057 100644 --- a/src/Message/Middleware/Middleware.php +++ b/src/Message/Translator/Translator.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -interface Middleware +interface Translator { /** @return list */ public function __invoke(Message $message): array; diff --git a/src/Message/Middleware/UntilEventMiddleware.php b/src/Message/Translator/UntilEventTranslator.php similarity index 83% rename from src/Message/Middleware/UntilEventMiddleware.php rename to src/Message/Translator/UntilEventTranslator.php index 9964fe0ba..d49e9b9c1 100644 --- a/src/Message/Middleware/UntilEventMiddleware.php +++ b/src/Message/Translator/UntilEventTranslator.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Message\Middleware; +namespace Patchlevel\EventSourcing\Message\Translator; use DateTimeImmutable; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; use Patchlevel\EventSourcing\Message\Message; -final class UntilEventMiddleware implements Middleware +final class UntilEventTranslator implements Translator { public function __construct( private readonly DateTimeImmutable $until, diff --git a/tests/Unit/Message/Middleware/ChainMiddlewareTest.php b/tests/Unit/Message/Translator/ChainTranslatorTest.php similarity index 62% rename from tests/Unit/Message/Middleware/ChainMiddlewareTest.php rename to tests/Unit/Message/Translator/ChainTranslatorTest.php index f6fd954de..6756d3c87 100644 --- a/tests/Unit/Message/Middleware/ChainMiddlewareTest.php +++ b/tests/Unit/Message/Translator/ChainTranslatorTest.php @@ -2,19 +2,19 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\ChainMiddleware; -use Patchlevel\EventSourcing\Message\Middleware\Middleware; +use Patchlevel\EventSourcing\Message\Translator\ChainTranslator; +use Patchlevel\EventSourcing\Message\Translator\Translator; 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\Message\Middleware\ChainMiddleware */ -final class ChainMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\ChainTranslator */ +final class ChainTranslatorTest extends TestCase { use ProphecyTrait; @@ -27,17 +27,17 @@ public function testChain(): void ), ); - $child1 = $this->prophesize(Middleware::class); + $child1 = $this->prophesize(Translator::class); $child1->__invoke($message)->willReturn([$message])->shouldBeCalled(); - $child2 = $this->prophesize(Middleware::class); + $child2 = $this->prophesize(Translator::class); $child2->__invoke($message)->willReturn([$message])->shouldBeCalled(); - $middleware = new ChainMiddleware([ + $translator = new ChainTranslator([ $child1->reveal(), $child2->reveal(), ]); - $middleware($message); + $translator($message); } } diff --git a/tests/Unit/Message/Middleware/ExcludeArchivedEventMiddlewareTest.php b/tests/Unit/Message/Translator/ExcludeArchivedEventTranslatorTest.php similarity index 68% rename from tests/Unit/Message/Middleware/ExcludeArchivedEventMiddlewareTest.php rename to tests/Unit/Message/Translator/ExcludeArchivedEventTranslatorTest.php index cf5ca89a6..18128065a 100644 --- a/tests/Unit/Message/Middleware/ExcludeArchivedEventMiddlewareTest.php +++ b/tests/Unit/Message/Translator/ExcludeArchivedEventTranslatorTest.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\ExcludeArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\ExcludeArchivedEventTranslator; 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\Message\Middleware\ExcludeArchivedEventMiddleware */ -final class ExcludeArchivedEventMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\ExcludeArchivedEventTranslator */ +final class ExcludeArchivedEventTranslatorTest extends TestCase { public function testExcludedEvent(): void { - $middleware = new ExcludeArchivedEventMiddleware(); + $translator = new ExcludeArchivedEventTranslator(); $message = Message::create( new ProfileCreated( @@ -26,14 +26,14 @@ public function testExcludedEvent(): void ), )->withHeader(new ArchivedHeader(true)); - $result = $middleware($message); + $result = $translator($message); self::assertSame([], $result); } public function testIncludeEvent(): void { - $middleware = new ExcludeArchivedEventMiddleware(); + $translator = new ExcludeArchivedEventTranslator(); $message = Message::create( new ProfileCreated( @@ -42,14 +42,14 @@ public function testIncludeEvent(): void ), )->withHeader(new ArchivedHeader(false)); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } public function testHeaderNotSet(): void { - $middleware = new ExcludeArchivedEventMiddleware(); + $translator = new ExcludeArchivedEventTranslator(); $message = Message::create( new ProfileCreated( @@ -58,7 +58,7 @@ public function testHeaderNotSet(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } diff --git a/tests/Unit/Message/Middleware/ExcludeEventMiddlewareTest.php b/tests/Unit/Message/Translator/ExcludeEventTranslatorTest.php similarity index 65% rename from tests/Unit/Message/Middleware/ExcludeEventMiddlewareTest.php rename to tests/Unit/Message/Translator/ExcludeEventTranslatorTest.php index f8d00c1d8..773997448 100644 --- a/tests/Unit/Message/Middleware/ExcludeEventMiddlewareTest.php +++ b/tests/Unit/Message/Translator/ExcludeEventTranslatorTest.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\ExcludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\ExcludeEventTranslator; 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\Message\Middleware\ExcludeEventMiddleware */ -final class ExcludeEventMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\ExcludeEventTranslator */ +final class ExcludeEventTranslatorTest extends TestCase { public function testDeleteEvent(): void { - $middleware = new ExcludeEventMiddleware([ProfileCreated::class]); + $translator = new ExcludeEventTranslator([ProfileCreated::class]); $message = new Message( new ProfileCreated( @@ -26,14 +26,14 @@ public function testDeleteEvent(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([], $result); } public function testSkipEvent(): void { - $middleware = new ExcludeEventMiddleware([ProfileCreated::class]); + $translator = new ExcludeEventTranslator([ProfileCreated::class]); $message = new Message( new ProfileVisited( @@ -41,7 +41,7 @@ public function testSkipEvent(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } diff --git a/tests/Unit/Message/Middleware/FilterEventMiddlewareTest.php b/tests/Unit/Message/Translator/FilterEventTranslatorTest.php similarity index 68% rename from tests/Unit/Message/Middleware/FilterEventMiddlewareTest.php rename to tests/Unit/Message/Translator/FilterEventTranslatorTest.php index f8c3903f4..119a61a6f 100644 --- a/tests/Unit/Message/Middleware/FilterEventMiddlewareTest.php +++ b/tests/Unit/Message/Translator/FilterEventTranslatorTest.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\FilterEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\FilterEventTranslator; 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\Message\Middleware\FilterEventMiddleware */ -final class FilterEventMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\FilterEventTranslator */ +final class FilterEventTranslatorTest extends TestCase { public function testPositive(): void { - $middleware = new FilterEventMiddleware(static function (object $event) { + $translator = new FilterEventTranslator(static function (object $event) { return $event instanceof ProfileCreated; }); @@ -28,14 +28,14 @@ public function testPositive(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } public function testNegative(): void { - $middleware = new FilterEventMiddleware(static function (object $event) { + $translator = new FilterEventTranslator(static function (object $event) { return $event instanceof ProfileCreated; }); @@ -45,7 +45,7 @@ public function testNegative(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([], $result); } diff --git a/tests/Unit/Message/Middleware/IncludeEventMiddlewareTest.php b/tests/Unit/Message/Translator/IncludeEventTranslatorTest.php similarity index 65% rename from tests/Unit/Message/Middleware/IncludeEventMiddlewareTest.php rename to tests/Unit/Message/Translator/IncludeEventTranslatorTest.php index 6489307e5..54458f198 100644 --- a/tests/Unit/Message/Middleware/IncludeEventMiddlewareTest.php +++ b/tests/Unit/Message/Translator/IncludeEventTranslatorTest.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\IncludeEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\IncludeEventTranslator; 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\Message\Middleware\IncludeEventMiddleware */ -final class IncludeEventMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\IncludeEventTranslator */ +final class IncludeEventTranslatorTest extends TestCase { public function testFilterEvent(): void { - $middleware = new IncludeEventMiddleware([ProfileCreated::class]); + $translator = new IncludeEventTranslator([ProfileCreated::class]); $message = new Message( new ProfileCreated( @@ -26,14 +26,14 @@ public function testFilterEvent(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } public function testSkipEvent(): void { - $middleware = new IncludeEventMiddleware([ProfileCreated::class]); + $translator = new IncludeEventTranslator([ProfileCreated::class]); $message = new Message( new ProfileVisited( @@ -41,7 +41,7 @@ public function testSkipEvent(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([], $result); } diff --git a/tests/Unit/Message/Middleware/OnlyArchivedEventMiddlewareTest.php b/tests/Unit/Message/Translator/OnlyArchivedEventTranslatorTest.php similarity index 69% rename from tests/Unit/Message/Middleware/OnlyArchivedEventMiddlewareTest.php rename to tests/Unit/Message/Translator/OnlyArchivedEventTranslatorTest.php index 9d105c262..a92c9e6f4 100644 --- a/tests/Unit/Message/Middleware/OnlyArchivedEventMiddlewareTest.php +++ b/tests/Unit/Message/Translator/OnlyArchivedEventTranslatorTest.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\OnlyArchivedEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\OnlyArchivedEventTranslator; 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\Message\Middleware\OnlyArchivedEventMiddleware */ -final class OnlyArchivedEventMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\OnlyArchivedEventTranslator */ +final class OnlyArchivedEventTranslatorTest extends TestCase { public function testExcludedEvent(): void { - $middleware = new OnlyArchivedEventMiddleware(); + $translator = new OnlyArchivedEventTranslator(); $message = Message::create( new ProfileCreated( @@ -26,14 +26,14 @@ public function testExcludedEvent(): void ), )->withHeader(new ArchivedHeader(false)); - $result = $middleware($message); + $result = $translator($message); self::assertSame([], $result); } public function testIncludeEvent(): void { - $middleware = new OnlyArchivedEventMiddleware(); + $translator = new OnlyArchivedEventTranslator(); $message = Message::create( new ProfileCreated( @@ -42,14 +42,14 @@ public function testIncludeEvent(): void ), )->withHeader(new ArchivedHeader(true)); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } public function testHeaderNotSet(): void { - $middleware = new OnlyArchivedEventMiddleware(); + $translator = new OnlyArchivedEventTranslator(); $message = Message::create( new ProfileCreated( @@ -58,7 +58,7 @@ public function testHeaderNotSet(): void ), ); - $result = $middleware($message); + $result = $translator($message); self::assertSame([], $result); } diff --git a/tests/Unit/Message/Middleware/RecalculatePlayheadMiddlewareTest.php b/tests/Unit/Message/Translator/RecalculatePlayheadTranslatorTest.php similarity index 79% rename from tests/Unit/Message/Middleware/RecalculatePlayheadMiddlewareTest.php rename to tests/Unit/Message/Translator/RecalculatePlayheadTranslatorTest.php index b1eca434e..a4ea92590 100644 --- a/tests/Unit/Message/Middleware/RecalculatePlayheadMiddlewareTest.php +++ b/tests/Unit/Message/Translator/RecalculatePlayheadTranslatorTest.php @@ -2,23 +2,23 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use DateTimeImmutable; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\RecalculatePlayheadMiddleware; +use Patchlevel\EventSourcing\Message\Translator\RecalculatePlayheadTranslator; 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\Message\Middleware\RecalculatePlayheadMiddleware */ -final class RecalculatePlayheadMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\RecalculatePlayheadTranslator */ +final class RecalculatePlayheadTranslatorTest extends TestCase { public function testRecalculatePlayhead(): void { - $middleware = new RecalculatePlayheadMiddleware(); + $translator = new RecalculatePlayheadTranslator(); $event = new ProfileCreated( ProfileId::fromString('1'), @@ -28,7 +28,7 @@ public function testRecalculatePlayhead(): void $message = Message::create($event) ->withHeader(new AggregateHeader('profile', '1', 5, new DateTimeImmutable())); - $result = $middleware($message); + $result = $translator($message); self::assertCount(1, $result); self::assertSame('profile', $result[0]->header(AggregateHeader::class)->aggregateName); @@ -37,7 +37,7 @@ public function testRecalculatePlayhead(): void public function testRecalculatePlayheadWithSamePlayhead(): void { - $middleware = new RecalculatePlayheadMiddleware(); + $translator = new RecalculatePlayheadTranslator(); $event = new ProfileCreated( ProfileId::fromString('1'), @@ -47,14 +47,14 @@ public function testRecalculatePlayheadWithSamePlayhead(): void $message = Message::create($event) ->withHeader(new AggregateHeader('profile', '1', 1, new DateTimeImmutable())); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } public function testRecalculateMultipleMessages(): void { - $middleware = new RecalculatePlayheadMiddleware(); + $translator = new RecalculatePlayheadTranslator(); $event = new ProfileCreated( ProfileId::fromString('1'), @@ -63,7 +63,7 @@ public function testRecalculateMultipleMessages(): void $message = Message::create($event) ->withHeader(new AggregateHeader('profile', '1', 5, new DateTimeImmutable())); - $result = $middleware($message); + $result = $translator($message); self::assertCount(1, $result); self::assertSame('profile', $result[0]->header(AggregateHeader::class)->aggregateName); @@ -72,7 +72,7 @@ public function testRecalculateMultipleMessages(): void $message = Message::create($event) ->withHeader(new AggregateHeader('profile', '1', 8, new DateTimeImmutable())); - $result = $middleware($message); + $result = $translator($message); self::assertCount(1, $result); self::assertSame('profile', $result[0]->header(AggregateHeader::class)->aggregateName); @@ -81,7 +81,7 @@ public function testRecalculateMultipleMessages(): void public function testReset(): void { - $middleware = new RecalculatePlayheadMiddleware(); + $translator = new RecalculatePlayheadTranslator(); $event = new ProfileCreated( ProfileId::fromString('1'), @@ -90,7 +90,7 @@ public function testReset(): void $message = Message::create($event) ->withHeader(new AggregateHeader('profile', '1', 5, new DateTimeImmutable())); - $result = $middleware($message); + $result = $translator($message); self::assertCount(1, $result); self::assertSame('profile', $result[0]->header(AggregateHeader::class)->aggregateName); @@ -99,8 +99,8 @@ public function testReset(): void $message = Message::create($event) ->withHeader(new AggregateHeader('profile', '1', 8, new DateTimeImmutable())); - $middleware->reset(); - $result = $middleware($message); + $translator->reset(); + $result = $translator($message); self::assertCount(1, $result); self::assertSame('profile', $result[0]->header(AggregateHeader::class)->aggregateName); diff --git a/tests/Unit/Message/Middleware/ReplaceEventMiddlewareTest.php b/tests/Unit/Message/Translator/ReplaceEventTranslatorTest.php similarity index 78% rename from tests/Unit/Message/Middleware/ReplaceEventMiddlewareTest.php rename to tests/Unit/Message/Translator/ReplaceEventTranslatorTest.php index 12cb8b579..6a5c2c731 100644 --- a/tests/Unit/Message/Middleware/ReplaceEventMiddlewareTest.php +++ b/tests/Unit/Message/Translator/ReplaceEventTranslatorTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\ReplaceEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\ReplaceEventTranslator; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\MessagePublished; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; @@ -13,12 +13,12 @@ use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; use PHPUnit\Framework\TestCase; -/** @covers \Patchlevel\EventSourcing\Message\Middleware\ReplaceEventMiddleware */ -final class ReplaceEventMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\ReplaceEventTranslator */ +final class ReplaceEventTranslatorTest extends TestCase { public function testReplace(): void { - $middleware = new ReplaceEventMiddleware( + $translator = new ReplaceEventTranslator( ProfileCreated::class, static function (ProfileCreated $event) { return new ProfileVisited( @@ -34,7 +34,7 @@ static function (ProfileCreated $event) { ), ); - $result = $middleware($message); + $result = $translator($message); self::assertCount(1, $result); @@ -46,7 +46,7 @@ static function (ProfileCreated $event) { public function testReplaceInvalidClass(): void { /** @psalm-suppress InvalidArgument */ - $middleware = new ReplaceEventMiddleware( + $translator = new ReplaceEventTranslator( MessagePublished::class, static function (ProfileCreated $event) { return new ProfileVisited( @@ -62,7 +62,7 @@ static function (ProfileCreated $event) { ), ); - $result = $middleware($message); + $result = $translator($message); self::assertCount(1, $result); diff --git a/tests/Unit/Message/Middleware/UntilEventMiddlewareTest.php b/tests/Unit/Message/Translator/UntilEventTranslatorTest.php similarity index 73% rename from tests/Unit/Message/Middleware/UntilEventMiddlewareTest.php rename to tests/Unit/Message/Translator/UntilEventTranslatorTest.php index 3cae0b31a..e1c8c3e1b 100644 --- a/tests/Unit/Message/Middleware/UntilEventMiddlewareTest.php +++ b/tests/Unit/Message/Translator/UntilEventTranslatorTest.php @@ -2,25 +2,25 @@ declare(strict_types=1); -namespace Patchlevel\EventSourcing\Tests\Unit\Message\Middleware; +namespace Patchlevel\EventSourcing\Tests\Unit\Message\Translator; use DateTimeImmutable; use Patchlevel\EventSourcing\Aggregate\AggregateHeader; use Patchlevel\EventSourcing\Message\Message; -use Patchlevel\EventSourcing\Message\Middleware\UntilEventMiddleware; +use Patchlevel\EventSourcing\Message\Translator\UntilEventTranslator; 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\Message\Middleware\UntilEventMiddleware */ -final class UntilEventMiddlewareTest extends TestCase +/** @covers \Patchlevel\EventSourcing\Message\Translator\UntilEventTranslator */ +final class UntilEventTranslatorTest extends TestCase { public function testPositive(): void { $until = new DateTimeImmutable('2020-02-02 00:00:00'); - $middleware = new UntilEventMiddleware($until); + $translator = new UntilEventTranslator($until); $message = Message::create( new ProfileCreated( @@ -29,7 +29,7 @@ public function testPositive(): void ), )->withHeader(new AggregateHeader('pofile', '1', 1, new DateTimeImmutable('2020-02-01 00:00:00'))); - $result = $middleware($message); + $result = $translator($message); self::assertSame([$message], $result); } @@ -38,7 +38,7 @@ public function testNegative(): void { $until = new DateTimeImmutable('2020-01-01 00:00:00'); - $middleware = new UntilEventMiddleware($until); + $translator = new UntilEventTranslator($until); $message = Message::create( new ProfileCreated( @@ -47,7 +47,7 @@ public function testNegative(): void ), )->withHeader(new AggregateHeader('pofile', '1', 1, new DateTimeImmutable('2020-02-01 00:00:00'))); - $result = $middleware($message); + $result = $translator($message); self::assertSame([], $result); }