/**
  * @test
  */
 public function it_deserialize_the_message_before_emitting()
 {
     $stream = new DomainEventStream([new DomainMessage('a', 0, new Metadata(), [], DateTime::now())]);
     $consumer = new EventBusConsumer($this->serializer, $this->eventBus);
     $this->serializer->shouldReceive('deserialize')->with("[]")->andReturn($stream);
     $this->eventBus->shouldReceive('publish')->with($stream)->once();
     $consumer->consume("[]");
 }
 /**
  * @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);
 }
 /**
  * @test
  */
 public function handleShouldPublishADomainMessage()
 {
     $error = \Mockery::mock(EventInterface::class);
     $this->eventBus->shouldReceive('publish')->with(\Mockery::on(function (DomainEventStream $eventStream) use($error) {
         $this->assertInstanceOf(DomainEventStream::class, $eventStream);
         $streamIterator = $eventStream->getIterator();
         $this->assertEquals(1, count($streamIterator));
         $message = $streamIterator[0];
         $this->assertEquals($error, $message->getPayload());
         return true;
     }))->once();
     $handler = new DomainMessageErrorEventHandler($this->eventBus);
     $handler->handle($error);
 }