Beispiel #1
0
 public function testMessageInfo()
 {
     $queue = $this->createQueue(__FUNCTION__);
     $adapter = $queue->getAdapter();
     $this->checkAdapterSupport('deleteQueue');
     $infoKey = $queue->getOptions()->getMessageMetadatumKey();
     $body = 'this is a test message';
     $message = new Message();
     $message->setContent($body);
     $message->setMetadata($infoKey, 'foo');
     $adapter->sendMessage($queue, $message);
     $messageInfo = $message->getMetadata($infoKey);
     //test message was cleaned
     $this->assertNotEquals('foo', $messageInfo);
     //test messageInfo is ok after send
     $this->checkMessageInfo($messageInfo, $queue);
     $message = $adapter->receiveMessages($queue)->current();
     $messageInfo = $message->getMetadata($infoKey);
     //test messageInfo is ok after receive
     $this->checkMessageInfo($messageInfo, $queue);
     // delete the queue we created
     $adapter->deleteQueue($queue->getName());
 }
Beispiel #2
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;
 }
Beispiel #3
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']);
 }