public function testAddSameChannelTwice()
 {
     $collection = new ChannelCollection();
     $channel = $this->getChannelMock('channel_one');
     $collection->addChannel($channel);
     $channel_duplicate = $this->getChannelMock('channel_one');
     $collection->addChannel($channel_duplicate);
     $this->assertCount(1, $collection->getChannels());
 }
Example #2
0
 public function parse($raw)
 {
     $buffer = new Buffer($raw);
     $channelLength = $buffer->readInt32BE(0);
     $channelList = $buffer->read(4, $channelLength);
     foreach (explode(',', $channelList) as $channelName) {
         $this->channels->addChannel(new Channel($channelName));
     }
     $this->message = $buffer->read(4 + $channelLength, $buffer->length() - (4 + $channelLength));
     $this->parsed = true;
 }
Example #3
0
 public function subscribe()
 {
     $channels = new ChannelCollection();
     foreach (func_get_args() as $channel) {
         $channels->addChannel(new Channel($channel));
     }
     $message = new SubscribeMessage($channels);
     $this->subscriber->subscribe($message);
 }
Example #4
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());
 }
<?php

require __DIR__ . '/../vendor/.composer/autoload.php';
use TrafficCophp\Network\SocketTransport;
use TrafficCophp\Publisher\Publisher;
use TrafficCophp\Subscriber\Subscriber;
use TrafficCophp\Message\SubscribeMessage;
use TrafficCophp\Message\PublishMessage;
use TrafficCophp\Channel\ChannelCollection;
use TrafficCophp\Channel\Channel;
use TrafficCophp\Message\ServerMessage;
$_ENV['traffic_cop_host'] = '127.0.0.1';
$_ENV['traffic_cop_port'] = 3542;
$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);
$subscriber->receive($message = new ServerMessage(new ChannelCollection()));
var_dump($message);