Exemplo n.º 1
0
 public function testSerialization()
 {
     $message = serialize($this->message);
     $woken = unserialize($message);
     $this->assertEquals($this->message->getContent(), $woken->getContent());
     $this->assertEquals($this->message->getMetadata(), $woken->getMetadata());
 }
Exemplo n.º 2
0
 public function testConstruct()
 {
     $message = new Message();
     $message->setContent('A message');
     $stdMessage = new ZendMessage();
     $stdMessage->setContent('A stdlib message');
     //Test array of Message, without queue in constructor
     $messages = new MessageIterator([$message, $stdMessage]);
     $this->assertEquals($message, $messages->current());
     $messages->next();
     $this->assertEquals($stdMessage, $messages->current());
     $this->assertNull($messages->getQueue());
     $this->assertNull($messages->getQueueClass());
     //Test array of array, without queue in constructor
     $messages = new MessageIterator([['content' => 'a message']]);
     $this->assertEquals('a message', $messages->current()->getContent());
     $this->assertInstanceOf($this->queue->getOptions()->getMessageClass(), $messages->current());
     //Test with queue in constructor
     $messages = new MessageIterator([$message, $stdMessage], $this->queue);
     $this->assertTrue($this->queue === $messages->getQueue());
     $this->assertEquals(get_class($this->queue), $this->messages->getQueueClass());
 }
Exemplo n.º 3
0
 /**
  * Create a send a message in order to dispatch another controller
  *
  * Expect that a worker will process the message using the forward strategy
  *
  * @param  string $name Controller name; either a class name or an alias used in the DI container or service locator
  * @param  null|array $params Parameters with which to seed a custom RouteMatch object for the new controller
  * @param  SendParametersInterface $sendParams
  * @return MessageInterface
  */
 public function dispatch($name, array $params = null, SendParametersInterface $sendParams = null)
 {
     $message = new Message();
     //TODO: use a custom message class?
     $message->setContent($name);
     if ($params !== null) {
         $message->setMetadata($params);
     }
     $this->getQueue()->send($message, $sendParams);
     return $message;
 }
Exemplo n.º 4
0
 public function testCountMessages()
 {
     $queue = $this->createQueue(__FUNCTION__);
     $adapter = $queue->getAdapter();
     // check to see if this function is supported
     if (!$adapter instanceof CountMessagesCapableInterface) {
         $this->markTestSkipped('countMessages() is not supported');
         return;
     }
     $this->checkAdapterSupport('deleteQueue');
     // for a test case, the count should be zero at first.
     $this->assertEquals($adapter->countMessages($queue), 0);
     $body = 'this is a test message';
     // send a message
     $message = new Message();
     $message->setContent($body);
     if (!$adapter->sendMessage($queue, $message)) {
         $this->fail('sendMessage() failed');
     }
     // test queue count for being 1
     /* @var $adapter CountMessagesCapableInterface */
     $this->assertEquals($adapter->countMessages($queue), 1);
     // receive the message
     $message = $adapter->receiveMessages($queue);
     /* we need to delete the messages we put in the queue before
      * counting.
      *
      * not all adapters support deleteMessage, but we should remove
      * the messages that we created if we can.
      */
     if ($adapter instanceof DeleteMessageCapableInterface) {
         foreach ($message as $msg) {
             /* @var $adapter DeleteMessageCapableInterface */
             $adapter->deleteMessage($queue, $msg);
         }
         // test the count for being 0
         $this->assertEquals($adapter->countMessages($queue), 0);
     }
     // delete the queue we created
     $adapter->deleteQueue($queue->getName());
 }
Exemplo n.º 5
0
 public function testUnscheduleMessage()
 {
     $message = new Message();
     $providedOptions = [SendParameters::SCHEDULE => time() + 60, SendParameters::REPEATING_INTERVAL => 3600];
     $mockAdapter = $this->getMock(Adapter\Capabilities\DeleteMessageCapableInterface::class);
     $mockAdapter->expects($this->any())->method('getAvailableSendParams')->will($this->returnValue([SendParameters::SCHEDULE, SendParameters::REPEATING_INTERVAL]));
     /** @var $mockAdapter Adapter\AdapterInterface */
     $q = new Queue('test', $mockAdapter);
     $message->setMetadata($q->getOptions()->getMessageMetadatumKey(), ['options' => $providedOptions]);
     /** @var $mockAdapter \PHPUnit_Framework_MockObject_MockObject */
     $mockAdapter->expects($this->any())->method('getMessageInfo')->with($this->equalTo($q), $this->equalTo($message))->will($this->returnValue(['options' => $providedOptions]));
     $mockAdapter->expects($this->any())->method('deleteMessage')->with($this->equalTo($q), $this->equalTo($message))->will($this->returnValue(true));
     $this->assertTrue($q->isSendParamSupported(SendParameters::SCHEDULE));
     $this->assertTrue($q->isSendParamSupported(SendParameters::REPEATING_INTERVAL));
     $this->assertTrue($q->unschedule($message));
     $messageInfo = $message->getMetadata($q->getOptions()->getMessageMetadatumKey());
     $this->assertArrayHasKey('options', $messageInfo);
     $this->assertArrayNotHasKey(SendParameters::SCHEDULE, $messageInfo['options']);
     $this->assertArrayNotHasKey(SendParameters::REPEATING_INTERVAL, $messageInfo['options']);
 }