Exemplo n.º 1
0
 public function testRepeatingIntervalInvalidArgument()
 {
     $this->setExpectedException(InvalidArgumentException::class);
     $this->sendParameter->setRepeatingInterval('fndfnfbd');
 }
Exemplo n.º 2
0
 public function testScheduleMessage()
 {
     $time = time() + 3600;
     $repeting = 60;
     $message = new Message();
     $expectedParams = new SendParameters();
     $expectedParams->setSchedule($time);
     $expectedParams->setRepeatingInterval($repeting);
     $mockAdapter = $this->getMock(Adapter\AdapterInterface::class);
     $mockAdapter->expects($this->any())->method('getAvailableSendParams')->will($this->returnValue([SendParameters::SCHEDULE, SendParameters::REPEATING_INTERVAL]));
     /** @var $mockAdapter Adapter\AdapterInterface */
     $q = new Queue('test', $mockAdapter);
     /** @var $mockAdapter \PHPUnit_Framework_MockObject_MockObject */
     $mockAdapter->expects($this->any())->method('sendMessage')->with($this->equalTo($q), $this->equalTo($message), $this->equalTo($expectedParams))->will($this->returnValue($message));
     $this->assertTrue($q->isSendParamSupported(SendParameters::SCHEDULE));
     $this->assertTrue($q->isSendParamSupported(SendParameters::REPEATING_INTERVAL));
     $this->assertSame($message, $q->schedule($message, $time, $repeting));
 }
Exemplo n.º 3
0
 /**
  * Schedule a message to the queue
  *
  * @param  mixed $message message
  * @param  int $scheduleTime
  * @param  int $repeatingInterval
  * @param  SendParametersInterface $params
  * @return MessageInterface
  * @throws Exception\UnsupportedMethodCallException
  */
 public function schedule($message, $scheduleTime = null, $repeatingInterval = null, SendParametersInterface $params = null)
 {
     if (!$this->isSendParamSupported(SendParametersInterface::SCHEDULE)) {
         throw new Exception\UnsupportedMethodCallException(sprintf('"%s"" param is not supported by "%s"', SendParametersInterface::SCHEDULE, get_class($this->getAdapter())));
     }
     if ($repeatingInterval !== null && !$this->isSendParamSupported(SendParametersInterface::REPEATING_INTERVAL)) {
         throw new Exception\InvalidArgumentException(sprintf('"%s"" param is not supported by "%s"', SendParametersInterface::REPEATING_INTERVAL, get_class($this->getAdapter())));
     }
     if ($params === null) {
         $params = new SendParameters();
     }
     $params->setSchedule($scheduleTime)->setRepeatingInterval($repeatingInterval);
     return $this->send($message, $params);
 }
 /**
  * Execute the request
  *
  * @param  MvcEvent $e
  * @return mixed
  * @throws Exception\DomainException
  */
 public function onDispatch(MvcEvent $e)
 {
     $routeMatch = $e->getRouteMatch();
     if (!$routeMatch) {
         /**
          * @todo Determine requirements for when route match is missing.
          *       Potentially allow pulling directly from request metadata?
          */
         throw new \Zend\Mvc\Exception\DomainException('Missing route matches; unsure how to retrieve action');
     }
     $action = $routeMatch->getParam('action', null);
     if ($action) {
         $action = strtolower($action);
     }
     switch ($action) {
         case 'process':
             $message = $routeMatch->getParam('message', null);
             if ($message instanceof MessageInterface) {
                 $result = $this->process($message);
             } else {
                 throw new \InvalidArgumentException('Missing or invalid message type: must be an instace of ' . MessageInterface::class);
             }
             break;
         case 'send':
         case 'receive':
         case 'await':
             $queue = $routeMatch->getParam('queue', null);
             if (is_string($queue)) {
                 $queue = $this->getServiceLocator()->get($queue);
             }
             if (!$queue instanceof QueueClientInterface) {
                 throw new \InvalidArgumentException('Invalid queue param type: must be a string or an instace of ' . QueueClientInterface::class);
             }
             if ($action === 'send') {
                 $message = $routeMatch->getParam('message', null);
                 $parameters = $routeMatch->getParam('sendParameters', null);
                 if ($parameters === null) {
                     $params = null;
                 } else {
                     if ($parameters instanceof SendParametersInterface) {
                         $params = $parameters;
                     } else {
                         if (is_string($parameters)) {
                             $params = new SendParameters();
                             $params->fromString($parameters);
                         } else {
                             if (is_array($parameters)) {
                                 $params = new SendParameters();
                                 $params->fromArray($parameters);
                             } else {
                                 throw new \InvalidArgumentException('Invalid sendParameters param type: must be null, an array, a string or an instace of ' . SendParametersInterface::class);
                             }
                         }
                     }
                 }
                 $result = $this->send($queue, $message, $params);
             } else {
                 $parameters = $routeMatch->getParam('receiveParameters', null);
                 if ($parameters === null) {
                     $params = null;
                 } else {
                     if ($parameters instanceof ReceiveParametersInterface) {
                         $params = $parameters;
                     } else {
                         if (is_string($parameters)) {
                             $params = new ReceiveParameters();
                             $params->fromString($parameters);
                         } else {
                             if (is_array($parameters)) {
                                 $params = new ReceiveParameters();
                                 $params->fromArray($parameters);
                             } else {
                                 throw new \InvalidArgumentException('Invalid receiveParameters param type: must be null, an array, a string or an instace of ' . QueueClientInterface::class);
                             }
                         }
                     }
                 }
                 if ($action === 'receive') {
                     $maxMessages = (int) $routeMatch->getParam('maxMessages', 1);
                     $result = $this->receive($queue, $maxMessages, $params);
                 } else {
                     $result = $this->await($queue, $params);
                 }
             }
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid action "%s". Only "process", "send", "receive", "await" are allowed', $action));
     }
     $e->setResult($result);
     return $result;
 }