/**
  * @test
  */
 public function it_wraps_a_prooph_message()
 {
     $proophMessage = $this->prophesize(Message::class);
     $proophMessage->messageName()->willReturn('prooph-message');
     $bernardMessage = BernardMessage::fromProophMessage($proophMessage->reveal());
     $this->assertEquals('prooph-message', $bernardMessage->getName());
     $this->assertSame($proophMessage->reveal(), $bernardMessage->getProophMessage());
 }
 /**
  * @param $serialized
  * @return Envelope
  */
 public function unserialize($serialized)
 {
     $data = json_decode($serialized, true);
     $messageData = $data['message'];
     $messageData['created_at'] = \DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:s.u', $messageData['created_at'], new \DateTimeZone('UTC'));
     $proophMessage = $this->messageFactory->createMessageFromArray($messageData['message_name'], $messageData);
     $envelope = new Envelope(BernardMessage::fromProophMessage($proophMessage));
     return $envelope;
 }
 /**
  * @test
  */
 public function it_serializes_and_unserializes_a_message()
 {
     $doSomethingCommand = new DoSomething(['data' => 'some test data']);
     $bernardMessage = BernardMessage::fromProophMessage($doSomethingCommand);
     $envelope = new Envelope($bernardMessage);
     $bernardSerializer = new BernardSerializer(new FQCNMessageFactory(), new NoOpMessageConverter());
     $serializedEnvelope = $bernardSerializer->serialize($envelope);
     $unserializedEnvelope = $bernardSerializer->unserialize($serializedEnvelope);
     $this->assertEquals($envelope->getTimestamp(), $unserializedEnvelope->getTimestamp());
     $this->assertEquals($envelope->getMessage()->getProophMessage()->toArray(), $unserializedEnvelope->getMessage()->getProophMessage()->toArray());
 }
 /**
  * @test
  */
 public function it_dispatches_an_event_on_the_event_bus()
 {
     $proophMessage = $this->prophesize(Message::class);
     $proophMessage->messageType()->willReturn('event');
     $commandBus = $this->prophesize(CommandBus::class);
     $eventBus = $this->prophesize(EventBus::class);
     $commandBus->dispatch($proophMessage->reveal())->shouldNotBeCalled();
     $eventBus->dispatch($proophMessage->reveal())->shouldBeCalled();
     $bernardMessage = BernardMessage::fromProophMessage($proophMessage->reveal());
     $bernardRouter = new BernardRouter($commandBus->reveal(), $eventBus->reveal());
     $bernardRouter->routeMessage($bernardMessage);
 }
 /**
  * @param Message $message
  * @return BernardMessage
  */
 private function toBernardMessage(Message $message)
 {
     return BernardMessage::fromProophMessage($message);
 }