/**
  * @test
  */
 public function itShouldRollbackAfterPublishingFailed()
 {
     $stream = \Mockery::mock(DomainEventStreamInterface::class);
     $this->transactionManager->shouldReceive('beginTransaction')->once();
     $this->transactionManager->shouldReceive('rollback')->once();
     $this->eventBus->shouldReceive('publish')->with($stream)->andThrow(\Exception::class);
     $this->setExpectedException(\Exception::class);
     $eventBus = new TransactionalEventBus($this->eventBus, $this->transactionManager);
     $eventBus->publish($stream);
 }
 /**
  * Publishes the events from the domain event stream to the listeners.
  *
  * @param DomainEventStreamInterface $domainMessages
  * @throws \Exception
  */
 public function publish(DomainEventStreamInterface $domainMessages)
 {
     $this->transactionManager->beginTransaction();
     try {
         $this->eventBus->publish($domainMessages);
         $this->transactionManager->commit();
     } catch (\Exception $e) {
         $this->transactionManager->rollback();
         throw $e;
     }
 }