Ejemplo n.º 1
0
 /**
  * Starts an infinite loop calling Consumer::tick();
  *
  * @param string $queue
  * @param array  $options
  */
 public function consume($queue, array $options = [])
 {
     $backend = $this->backendProvider->getBackend($queue);
     $backend->initialize();
     declare (ticks=1);
     while ($this->tick($backend, $options)) {
         // NO op
     }
 }
Ejemplo n.º 2
0
 public function testConsumeIteratesOverAllMessages()
 {
     $queue = 'foobar';
     $message = $this->createMock(MessageInterface::class);
     $iterator = new TestIterator([$message, $message]);
     $this->backendProvider->expects($this->any())->method('getBackend')->with($queue)->willReturn($this->backend);
     $this->backend->expects($this->any())->method('getIterator')->willReturn($iterator);
     $this->backend->expects($this->exactly(2))->method('handle');
     // the $iterator does not pop elements so we have to make sure ->tick() does not iterate over the same array multiple times
     $this->subject->consume($queue, ['stop-when-empty' => true]);
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \Exception
  */
 public function testProduceThrowsExceptionsThrownByBackend()
 {
     $queue = 'foobar';
     $message = new Message('type', 'ticket', 'callback');
     $backend = $this->createMock(BackendInterface::class);
     $jobType = $this->createMock(JobTypeInterface::class);
     $jobType->expects($this->any())->method('getQueue')->willReturn($queue);
     $this->registry->expects($this->any())->method('get')->with('type')->willReturn($jobType);
     $this->backendProvider->expects($this->once())->method('getBackend')->with($queue)->willReturn($backend);
     $backend->expects($this->once())->method('createAndPublish')->willThrowException(new \Exception());
     $this->subject->produce($message);
 }