/** * @test * @dataProvider idDataProvider */ public function it_appends_to_an_already_existing_stream($id) { $dateTime = new \DateTimeImmutable("now"); $domainEventStream = new EventStream(new StreamName('event_stream'), [$this->createDomainMessage($id, 0, $dateTime), $this->createDomainMessage($id, 1, $dateTime), $this->createDomainMessage($id, 2, $dateTime)]); $this->eventStore->append($domainEventStream); $appendedEventStream = new EventStream(new StreamName('event_stream'), [$this->createDomainMessage($id, 3, $dateTime), $this->createDomainMessage($id, 4, $dateTime), $this->createDomainMessage($id, 5, $dateTime)]); $this->eventStore->append($appendedEventStream); $expected = new EventStream(new StreamName('event_stream'), [$this->createDomainMessage($id, 0, $dateTime), $this->createDomainMessage($id, 1, $dateTime), $this->createDomainMessage($id, 2, $dateTime), $this->createDomainMessage($id, 3, $dateTime), $this->createDomainMessage($id, 4, $dateTime), $this->createDomainMessage($id, 5, $dateTime)]); $this->assertEquals($expected, $this->eventStore->getEventsFor(new StreamName('event_stream'), $id)); }
/** * {@inheritDoc} */ public function save(AggregateRootInterface $aggregate, StreamName $streamName = null) { $streamName = $this->determineStreamName($streamName); $eventStream = new EventStream($streamName, $aggregate->getUncommittedEvents()); $this->eventStore->append($eventStream); $eventStream->each(function (DomainMessage $domainMessage) { $this->eventBus->publish($domainMessage->getPayload()); })->each(function (DomainMessage $domainMessage) use($streamName, $aggregate) { if ($this->snapshotter) { $this->snapshotter->take($streamName, $aggregate, $domainMessage); } }); }
private function setUpForEventStream(EventStream $stream) { $this->eventStore = $this->prophesize(EventStoreInterface::class); $this->eventStore->append($stream)->shouldBeCalled(); $this->eventBus = $this->prophesize(EventBusInterface::class); $stream->each(function (DomainMessage $domainMessage) { $this->eventBus->publish($domainMessage->getPayload())->shouldBeCalled(); }); }