コード例 #1
0
ファイル: PubSubTest.php プロジェクト: so-php/pubsub
 public function testPublishMergesParamsWithSuppliedEventParams()
 {
     $event = new Event(uniqid(), preg_split('//', uniqid()));
     $params2 = preg_split('//', uniqid());
     // set up expectation so that if our callback never runs the test fails
     $objMock = $this->getMock('stdClass', array('test'));
     $objMock->expects($this->once())->method('test')->with($event->getName(), array_merge($event->getParams(), $params2));
     $this->exchangeDescriptorMock->setName(uniqid());
     $this->channelMock->expects($this->once())->method('basic_publish')->with($this->isInstanceOf('\\PhpAmqpLib\\Message\\AMQPMessage'), $this->exchangeDescriptorMock->getName())->will($this->returnCallback(function (AMQPMessage $msg) use($objMock) {
         $reconstructedEvent = Event::fromJson($msg->body);
         // attempt to satisfy our expectation
         $objMock->test($reconstructedEvent->getName(), $reconstructedEvent->getParams());
     }));
     $this->pubSub->publish($event, $params2);
 }
コード例 #2
0
ファイル: PubSub.php プロジェクト: so-php/pubsub
 /**
  * @param AMQPMessage $message
  */
 public function onMessage(AMQPMessage $message)
 {
     $event = Event::fromJson($message->body);
     if (isset($this->listeners[$event->getName()])) {
         foreach ($this->listeners[$event->getName()] as $callback) {
             call_user_func($callback, $event, $message);
         }
     }
 }