Example #1
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);
 }
Example #2
0
 public function testSetScheduleInvalidArgument()
 {
     $this->setExpectedException(InvalidArgumentException::class);
     $this->sendParameter->setSchedule('fndfnfbd');
 }
Example #3
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));
 }