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(); }
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()); }
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); } }