/** * This method takes domain events as argument which are going to be added to the event stream and * adds the causation_id (command UUID) and causation_name (name of the command which has caused the events) * as metadata to each event. * * @param Iterator $recordedEvents * @return Iterator */ private function handleRecordedEvents(Iterator $recordedEvents) { if (is_null($this->currentCommand) || !$this->currentCommand instanceof Message) { return $recordedEvents; } $causationId = $this->currentCommand->uuid()->toString(); $causationName = $this->currentCommand->messageName(); $enrichedRecordedEvents = []; foreach ($recordedEvents as $recordedEvent) { $recordedEvent = $recordedEvent->withAddedMetadata('causation_id', $causationId); $recordedEvent = $recordedEvent->withAddedMetadata('causation_name', $causationName); $enrichedRecordedEvents[] = $recordedEvent; } return new ArrayIterator($enrichedRecordedEvents); }
/** * @test */ public function it_has_a_name() { $this->assertEquals('TestCommand', $this->command->messageName()); }