diff --git a/composer.json b/composer.json index 00548dc..fdb4122 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { "php": ">=5.5", - "prooph/event-store" : "^5.1", + "prooph/event-store" : "dev-develop", "prooph/service-bus" : "^4.0" }, "require-dev": { diff --git a/src/TransactionManager.php b/src/TransactionManager.php index b81bea8..481faff 100644 --- a/src/TransactionManager.php +++ b/src/TransactionManager.php @@ -10,6 +10,8 @@ */ namespace Prooph\EventStoreBusBridge; +use Iterator; +use ArrayIterator; use Prooph\Common\Event\ActionEvent; use Prooph\Common\Event\ActionEventEmitter; use Prooph\Common\Event\ActionEventListenerAggregate; @@ -74,10 +76,10 @@ public function attach(ActionEventEmitter $emitter) * adds the causation_id (command UUID) and causation_name (name of the command which has caused the events) * as metadata to each event. * - * @param Message[] $recordedEvents - * @return Message[] + * @param Iterator $recordedEvents + * @return Iterator */ - private function handleRecordedEvents(array $recordedEvents) + private function handleRecordedEvents(Iterator $recordedEvents) { if (is_null($this->currentCommand) || ! $this->currentCommand instanceof Message) { return $recordedEvents; @@ -95,7 +97,7 @@ private function handleRecordedEvents(array $recordedEvents) $enrichedRecordedEvents[] = $recordedEvent; } - return $enrichedRecordedEvents; + return new ArrayIterator($enrichedRecordedEvents); } /** diff --git a/tests/TransactionManagerTest.php b/tests/TransactionManagerTest.php index 85fff23..b32754c 100644 --- a/tests/TransactionManagerTest.php +++ b/tests/TransactionManagerTest.php @@ -196,7 +196,7 @@ public function it_adds_causation_id_and_causation_name_on_event_store_create_st $recordedEventCopy1->withAddedMetadata('causation_name', 'causation-message-name')->willReturn($recordedEventCopy2->reveal()); $recordedEvent->withAddedMetadata('causation_id', $causationId->toString())->willReturn($recordedEventCopy1->reveal()); - $stream = new Stream(new StreamName('event_stream'), [$recordedEvent->reveal()]); + $stream = new Stream(new StreamName('event_stream'), new \ArrayIterator([$recordedEvent->reveal()])); $createStreamActionEvent = $this->prophesize(ActionEvent::class); @@ -254,7 +254,7 @@ public function it_adds_causation_id_and_causation_name_on_event_store_append_to $appendToStreamActionEvent = $this->prophesize(ActionEvent::class); - $appendToStreamActionEvent->getParam('streamEvents')->willReturn([$recordedEvent->reveal()]); + $appendToStreamActionEvent->getParam('streamEvents')->willReturn(new \ArrayIterator([$recordedEvent->reveal()])); $enrichedEvents = null; $appendToStreamActionEvent->setParam('streamEvents', Argument::any()) @@ -265,7 +265,7 @@ public function it_adds_causation_id_and_causation_name_on_event_store_append_to $transactionManager->onEventStoreAppendToStream($appendToStreamActionEvent->reveal()); $this->assertNotNull($enrichedEvents); - $this->assertTrue(is_array($enrichedEvents)); + $this->assertInstanceOf(\ArrayIterator::class, $enrichedEvents); $this->assertEquals(1, count($enrichedEvents)); $this->assertSame($recordedEventCopy2->reveal(), $enrichedEvents[0]); } @@ -310,7 +310,7 @@ public function it_returns_early_if_command_was_null_when_handling_events() $recordedEvent->withAddedMetadata('causation_id', Argument::any())->shouldNotBeCalled(); - $stream = new Stream(new StreamName('event_stream'), [$recordedEvent->reveal()]); + $stream = new Stream(new StreamName('event_stream'), new \ArrayIterator([$recordedEvent->reveal()])); $createStreamActionEvent = new DefaultActionEvent('test'); $createStreamActionEvent->setParam('stream', $stream);