/**
  * @test
  */
 public function acks()
 {
     $message = Message::create('lus');
     $this->ed->expects($this->once())->method('dispatch')->with(Events::ACK, $this->isInstanceOf('Pekkis\\Queue\\SymfonyBridge\\MessageEvent'));
     $this->innerqueue->expects($this->once())->method('ack')->with($message)->will($this->returnValue(true));
     $ret = $this->queue->ack($message);
     $this->assertTrue($ret);
 }
 public function setUp()
 {
     $this->message = Message::create('lussuti.lus');
     $this->ed = new EventDispatcher();
     $this->output = $this->getMock('Symfony\\Component\\Console\\Output\\ConsoleOutputInterface');
     $subscriber = new ConsoleOutputSubscriber($this->output);
     $this->ed->addSubscriber($subscriber);
 }
 /**
  * @test
  */
 public function handles()
 {
     $data = new SerializedCallback('\\touchMyTrallala', ['xooxer']);
     $message = Message::create('xoo.lus', $data);
     $this->assertFileNotExists(ROOT_TESTS . '/data/temp/ping.txt');
     $handler = new FilelibMessageHandler();
     $handler->handle($message, $this->prophesize('Pekkis\\Queue\\Queue')->reveal());
     $this->assertFileExists(ROOT_TESTS . '/data/temp/ping.txt');
 }
Beispiel #4
0
 /**
  * @param string $topic
  * @param mixed $data
  * @return Message
  * @throws RuntimeException
  */
 public function enqueue($topic, $data = null)
 {
     $serializer = $this->dataSerializers->getSerializerFor($data);
     if (!$serializer) {
         throw new RuntimeException("Serializer not found");
     }
     $serializedData = new SerializedData($serializer->getIdentifier(), $serializer->serialize($data));
     $message = Message::create($topic, $data);
     $arr = array('uuid' => $message->getUuid(), 'topic' => $message->getTopic(), 'data' => $serializedData->toJson());
     $json = json_encode($arr);
     $json = $this->outputFilters->filter($json);
     try {
         $this->adapter->enqueue($json, $topic);
         return $message;
     } catch (\Exception $e) {
         throw new RuntimeException('Queuing a message failed', 0, $e);
     }
 }
Beispiel #5
0
 /**
  * @test
  * @dataProvider provideData
  */
 public function messagesAreHandled($successfulResult)
 {
     $message = Message::create('test', array('banana' => 'is not just a banaana, banaana'));
     $this->queue->expects($this->once())->method('dequeue')->will($this->returnValue($message));
     $mockHandler2 = $this->getMock('Pekkis\\Queue\\Processor\\MessageHandler');
     $mockHandler2->expects($this->never())->method('willHandle');
     $mockHandler = $this->getMock('Pekkis\\Queue\\Processor\\MessageHandler');
     $mockHandler->expects($this->once())->method('willHandle')->with($message)->will($this->returnValue(true));
     $message2 = Message::create('test', array('banana' => 'is not just a banaana, banaana'));
     $message3 = Message::create('test', array('banana' => 'is not just a banaana, banaana'));
     $result = new Result($successfulResult);
     $mockHandler->expects($this->once())->method('handle')->with($message, $this->queue)->will($this->returnValue($result));
     if ($successfulResult) {
         $this->queue->expects($this->once())->method('ack')->with($message);
     } else {
         $this->queue->expects($this->never())->method('ack');
     }
     $this->processor->registerHandler($mockHandler2);
     $this->processor->registerHandler($mockHandler);
     $this->processor->process();
 }
Beispiel #6
0
 /**
  * @test
  */
 public function ackDelegates()
 {
     $message = Message::create('test-message', array('aybabtu' => 'lussentus'));
     $this->adapter->expects($this->once())->method('ack')->will($this->returnValue('luslus'));
     $this->assertSame('luslus', $this->queue->ack($message));
 }
Beispiel #7
0
 /**
  * @test
  */
 public function setDataSetsData()
 {
     $message = Message::create('luss', array('mussutus' => 'kovaa mussutusta'));
     $message->setData('lussuttakeepa imaisua');
     $this->assertEquals('lussuttakeepa imaisua', $message->getData());
 }