/**
  * @test
  */
 public function itLosesMessageWhenThereIsNoHandlers()
 {
     $listener = new SomethingHappenedListener();
     $event = new SomethingHappened();
     $this->eventBus->publish($event);
     $this->eventBus->publish($event);
     $this->eventBus->publish($event);
     $this->assertSame(0, $listener->getCounter());
 }
 /**
  * {@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();
     });
 }