/**
  * @test createMessage creates new message with properties from envelope
  */
 public function copyPropertiesFromEnvelope()
 {
     $properties = ['body' => 'body message', 'headers' => ['x-header-1' => 'value1', 'x-header-2' => 'value2'], 'contentType' => 'application/json', 'contentEncoding' => 'utf-8', 'messageId' => '100', 'appId' => '2', 'userId' => '10', 'priority' => 3, 'timestamp' => strtotime('2012-12-18 09:45:11'), 'expiration' => 1000, 'type' => 'type_str', 'replyTo' => 'foo.bar'];
     $envelope = $this->createEnvelope($properties);
     $message = PeclMessageUtils::createMessage($envelope);
     $this->assertEquals($properties, CustomAmqpMessage::getMessageProperties($message));
 }
 /**
  * Create message from amqp envelope
  *
  * @param \AMQPEnvelope $envelope
  *
  * @return AmqpMessage
  */
 public static function createMessage(\AMQPEnvelope $envelope)
 {
     $properties = [];
     foreach (CustomAmqpMessage::getPropertyNames() as $name) {
         $properties[$name] = $envelope->{'get' . ucfirst($name)}();
     }
     return CustomAmqpMessage::fromProperties($properties);
 }
 /**
  * @param AmqpLibMessage $message
  *
  * @return AmqpMessage
  */
 public static function createMessage(AmqpLibMessage $message)
 {
     $properties = ['body' => $message->body];
     foreach (self::$PROPERTY_MAP as $name => $amqpLibName) {
         if ($message->has($amqpLibName)) {
             $properties[$name] = $message->get($amqpLibName);
         }
     }
     return CustomAmqpMessage::fromProperties($properties);
 }
 /**
  * {@inheritDoc}
  */
 public function eventToMessage(Event $event)
 {
     try {
         $msg = $this->prototype ? CustomAmqpMessage::createCopy($this->prototype) : new CustomAmqpMessage();
         $msg->setBody($this->serializer->serializeEvent($event));
         if ($event instanceof PriopritizedEvent) {
             $msg->setPriority($event->getPriority());
         }
         return $msg;
     } catch (SerializerException $e) {
         throw new EventConversionException($event, 'Serialize error', $e);
     }
 }
 /**
  * @test eventToMessage get properties from prototype
  */
 public function prototypeProperties()
 {
     $prototype = new AmqpMessageMock();
     $converter = new MessageSerializeConverter($this->serializer, $prototype);
     $event = $this->getMock('EventBand\\Event');
     $this->serializer->expects($this->once())->method('serializeEvent')->will($this->returnValue('serialized string'));
     $message = $converter->eventToMessage($event);
     $this->assertInstanceOf('EventBand\\Transport\\Amqp\\Driver\\AmqpMessage', $message);
     $messageProperties = CustomAmqpMessage::getMessageProperties($message);
     $expectedProperties = CustomAmqpMessage::getMessageProperties($prototype);
     $expectedProperties['body'] = 'serialized string';
     $this->assertEquals($expectedProperties, $messageProperties);
 }
 /**
  * @test copied message has same properties
  */
 public function copyMessageProperties()
 {
     $message = new AmqpMessageMock();
     $this->assertEquals(CustomAmqpMessage::getMessageProperties($message), CustomAmqpMessage::getMessageProperties(CustomAmqpMessage::createCopy($message)));
 }