Пример #1
0
 /**
  * @inheritdoc
  */
 public function publish(Message $message, \DateTime $date = null, $flags = ExchangeInterface::NOPARAM)
 {
     if ($date instanceof \DateTime) {
         $delay = $date->getTimestamp() - time();
         if ($delay < 0) {
             throw new \OutOFBoundsException('You cannot publish a message in the past');
         }
         // set delay in milliseconds
         $message->setHeader(MessageProperties::KEY_DELAY, $delay * 1000);
     }
     $body = $message->getBody();
     $route = $message->getRoutingKey();
     $props = $message->getProperties()->toArray();
     return $this->exchange->publish($body, $route, $flags, $props);
 }
 /**
  * @test
  * @expectedException        \OutOfBoundsException
  * @expectedExceptionMessage You cannot publish a message in the past
  */
 public function it_cannot_publish_a_message_in_the_past()
 {
     $message = $this->publisher->createMessage('test');
     $this->exchange->shouldReceive('publish')->never();
     $this->publisher->publish($message, new \DateTime('-10 minutes'));
 }