public function testConsuming()
 {
     $message = new Message('{"a": 10, "b": 15}', ['headers' => ['to' => 'phpunit']]);
     $queue = $this->channel->queue()->define(QueueInterface::FLAG_AUTO_DELETE);
     $this->channel->publish($message, '', $queue);
     $this->handler->expects($this->once())->method('handle')->willReturnCallback(function (Delivery $message) {
         $message->cancel();
     });
     $this->consumer->consume($queue);
 }
Exemplo n.º 2
0
 /**
  * Driver should compose AMQP message and publish it to the channel.
  */
 public function testPublish()
 {
     $reply = $this->getMockBuilder(Invoker\Reply::class)->disableOriginalConstructor()->getMock();
     $this->channel->expects($this->once())->method('publish')->willReturnCallback(function (Message $message, $exchange, $routingKey) use($reply) {
         $headers = ['base' => 'dec', 'topic' => 'add'];
         $this->assertJsonStringEqualsJsonString('{"a": 10, "b": 53}', $message->getBody());
         $this->assertEquals($headers, $message->getHeaders());
         $this->assertEquals($this->exchange, $exchange);
         $this->assertEquals('add', $routingKey);
         return $reply;
     });
     $this->driver->publish($this->createIdentity(), $this->createRequest());
 }
Exemplo n.º 3
0
 public function testCallReplyResolving()
 {
     $message = $this->createMessage();
     $this->channel->expects($this->once())->method('publish');
     $this->invoker->call($message, '', '')->resolve(10);
 }
Exemplo n.º 4
0
 /**
  * Create and publish reply message for given request message.
  *
  * @param Delivery $request
  * @param string   $body
  */
 private function reply(Delivery $request, $body)
 {
     $reply = new Message($body, ['correlation-id' => $request->getProperty('correlation-id')]);
     $this->channel->publish($reply, '', $request->getProperty('reply-to'));
 }