diff --git a/src/Message/Pipe.php b/src/Message/Pipe.php index 5b9750792..2c38bcdc3 100644 --- a/src/Message/Pipe.php +++ b/src/Message/Pipe.php @@ -18,17 +18,12 @@ final class Pipe implements IteratorAggregate { private Translator $translator; - /** - * @param iterable $messages - * @param list|Translator $translators - */ + /** @param iterable $messages */ public function __construct( private readonly iterable $messages, - array|Translator $translators = [], + Translator ...$translators, ) { - $this->translator = $translators instanceof Translator - ? $translators - : new ChainTranslator($translators); + $this->translator = new ChainTranslator($translators); } /** @return Traversable */ @@ -56,7 +51,9 @@ public function toArray(): array private function createGenerator(iterable $messages, Translator $translator): Generator { foreach ($messages as $message) { - yield from $translator($message); + foreach ($translator($message) as $translatedMessage) { + yield $translatedMessage; + } } } } diff --git a/tests/Integration/Subscription/Subscriber/MigrateAggregateToStreamStoreSubscriber.php b/tests/Integration/Subscription/Subscriber/MigrateAggregateToStreamStoreSubscriber.php index fd674133d..557bda0ed 100644 --- a/tests/Integration/Subscription/Subscriber/MigrateAggregateToStreamStoreSubscriber.php +++ b/tests/Integration/Subscription/Subscriber/MigrateAggregateToStreamStoreSubscriber.php @@ -56,7 +56,7 @@ public function beginBatch(): void public function commitBatch(): void { - $pipeline = new Pipe($this->messages, $this->middlewares); + $pipeline = new Pipe($this->messages, ...$this->middlewares); $this->messages = []; $this->targetStore->save(...$pipeline); diff --git a/tests/Unit/Message/PipeTest.php b/tests/Unit/Message/PipeTest.php index 4383545d6..1ffcf4d51 100644 --- a/tests/Unit/Message/PipeTest.php +++ b/tests/Unit/Message/PipeTest.php @@ -85,10 +85,8 @@ public function testWithMiddlewares(): void $stream = new Pipe( $messages, - [ - new ExcludeEventTranslator([ProfileCreated::class]), - new RecalculatePlayheadTranslator(), - ], + new ExcludeEventTranslator([ProfileCreated::class]), + new RecalculatePlayheadTranslator(), ); $resultMessages = iterator_to_array($stream); diff --git a/tests/Unit/Message/Translator/ChainTranslatorTest.php b/tests/Unit/Message/Translator/ChainTranslatorTest.php index 6756d3c87..9a1a9a998 100644 --- a/tests/Unit/Message/Translator/ChainTranslatorTest.php +++ b/tests/Unit/Message/Translator/ChainTranslatorTest.php @@ -18,6 +18,20 @@ final class ChainTranslatorTest extends TestCase { use ProphecyTrait; + public function testEmptyChain(): void + { + $message = new Message( + new ProfileCreated( + ProfileId::fromString('1'), + Email::fromString('hallo@patchlevel.de'), + ), + ); + + $translator = new ChainTranslator([]); + + self::assertSame([$message], $translator($message)); + } + public function testChain(): void { $message = new Message( @@ -38,6 +52,6 @@ public function testChain(): void $child2->reveal(), ]); - $translator($message); + self::assertSame([$message], $translator($message)); } }