Exemplo n.º 1
0
 public function testMessageToStringWorks()
 {
     $message = new Message();
     $message->setMetadata(array('Foo' => 'bar', 'One' => 'Two'));
     $message->setContent('This is my content');
     $expected = "Foo: bar\r\nOne: Two\r\n\r\nThis is my content";
     $this->assertEquals($expected, $message->toString());
 }
Exemplo n.º 2
0
 public function testSetGetMessage()
 {
     // Default
     $this->assertNull($this->event->getMessage());
     // Test
     $testValue = new Message();
     $testValue->setContent('bar');
     $this->assertSame($this->event, $this->event->setMessage($testValue));
     $this->assertSame($testValue, $this->event->getMessage());
 }
Exemplo n.º 3
0
 public function testConstruct()
 {
     $message = new Message();
     $message->setContent('A message');
     $stdMessage = new ZendMessage();
     $stdMessage->setContent('A stdlib message');
     //Test array of Message, without queue in constructor
     $messages = new MessageIterator([$message, $stdMessage]);
     $this->assertEquals($message, $messages->current());
     $messages->next();
     $this->assertEquals($stdMessage, $messages->current());
     $this->assertNull($messages->getQueue());
     $this->assertNull($messages->getQueueClass());
     //Test array of array, without queue in constructor
     $messages = new MessageIterator([['content' => 'a message']]);
     $this->assertEquals('a message', $messages->current()->getContent());
     $this->assertInstanceOf($this->queue->getOptions()->getMessageClass(), $messages->current());
     //Test with queue in constructor
     $messages = new MessageIterator([$message, $stdMessage], $this->queue);
     $this->assertTrue($this->queue === $messages->getQueue());
     $this->assertEquals(get_class($this->queue), $this->messages->getQueueClass());
 }
Exemplo n.º 4
0
 public function testMessageThrowsExceptionOnFromString()
 {
     $message = new Message();
     $this->setExpectedException('Zend\\Stdlib\\Exception\\DomainException');
     $message->fromString('some string');
 }
 /**
  * {@inheritdoc}
  */
 public function onDispatch(MvcEvent $e)
 {
     $this->registerDefaultProcessStrategy();
     //TEMP
     $routeMatch = $e->getRouteMatch();
     if ($routeMatch instanceof RouteMatch) {
         $message = $routeMatch->getParam('message', null);
         if ($message) {
             if (is_string($message)) {
                 $parameter = new Parameters();
                 $parameter->fromString($message);
                 $message = new Message();
                 $message->setContent($parameter->get('content'));
                 $message->setMetadata($parameter->get('metadata', []));
                 $routeMatch->setParam('message', $message);
             }
         } else {
             stream_set_blocking(STDIN, 0);
             $stdin = file_get_contents('php://stdin');
             $message = $this->getSerializer()->unserialize($stdin);
             $routeMatch->setParam('message', $message);
         }
         $cliPassthru = $routeMatch->getParam('cli-passthru', null);
         if ($cliPassthru) {
             $this->cliPassthru = sprintf('%s -f %s -- %s', PHP_BINARY, realpath($_SERVER['PHP_SELF']), $cliPassthru);
         }
     }
     return parent::onDispatch($e);
 }