예제 #1
0
 public function receive($func = null)
 {
     $this->subscriber->receive($message = new ServerMessage(new ChannelCollection()));
     if (is_callable($func)) {
         $channels = $message->getAddressedChannels();
         $channels->rewind();
         $func($channels->current()->getName(), $message->getMessage());
     }
     return $message->getMessage();
 }
예제 #2
0
 public function testSubscribeAndReceive()
 {
     $transport = new SocketTransport($_ENV['traffic_cop_host'], $_ENV['traffic_cop_port']);
     $subscriber = new Subscriber($transport);
     $channels = new ChannelCollection();
     $channels->addChannel(new Channel('channel_one'));
     $subscribeMessage = new SubscribeMessage($channels);
     $subscriber->subscribe($subscribeMessage);
     $test = new \TrafficCophp\Tests\Integration\PublisherTest();
     $test->testPublish();
     $subscriber->receive($message = new ServerMessage(new ChannelCollection()));
     $this->assertEquals('Hey there, im a message', $message->getMessage());
 }
예제 #3
0
 public function testGetAddressedChannelsWithMultipleChannels()
 {
     $rawChannels = array();
     $rawChannels[] = 'channel_one';
     $rawChannels[] = 'channel_two';
     $message = 'hello world';
     $srvMsg = new ServerMessage(new ChannelCollection());
     $srvMsg->parse($this->getRawData(implode(',', $rawChannels), $message));
     foreach ($srvMsg->getAddressedChannels() as $channel) {
         /* @var $channel \TrafficCophp\Channel\Channel */
         $this->assertContains($channel->getName(), $rawChannels);
     }
 }