public function setUp()
 {
     // stub an API instance to return AMQP messages
     $this->api = $this->getMockBuilder('\\eBayEnterprise\\RetailOrderManagement\\Api\\IAmqpApi')->disableOriginalConstructor()->getMockForAbstractClass();
     // stub an IOrderEvent payload to be returned from the message factory
     $this->payload = $this->getMockBuilder('\\eBayEnterprise\\RetailOrderManagement\\Payload\\IPayload')->disableOriginalConstructor()->setMethods(['deserialize'])->getMockForAbstractClass();
     $this->payload->expects($this->any())->method('deserialize')->will($this->returnSelf());
     // stub a message factory to return the stub payloads when processing messages off the queue
     $this->messageFactory = $this->getMockBuilder('\\eBayEnterprise\\RetailOrderManagement\\Payload\\IMessageFactory')->getMockForAbstractClass();
     $this->messageFactory->expects($this->any())->method('messagePayload')->will($this->returnValue($this->payload));
     // create the iterator to test and inject it with the stubs
     $this->iterator = new AmqpPayloadIterator($this->api, $this->messageFactory, self::MAX_MESSAGES);
 }
 /**
  * Get the appropriate payload type for the AMQP message and deserialize
  * the message body with the payload.
  * @param AMQPMessage $message
  * @throws Exception\UnexpectedResponse
  * @return IPayload
  */
 protected function processMessage(AMQPMessage $message)
 {
     try {
         $type = $message->get('type');
     } catch (OutOfBoundsException $e) {
         throw new Exception\UnexpectedResponse('No "type" set for message.');
     }
     $payload = $this->messageFactory->messagePayload($type);
     $payload->deserialize($message->body);
     return $payload;
 }