public function testPublish() { $transport = new SocketTransport($_ENV['traffic_cop_host'], $_ENV['traffic_cop_port']); $publisher = new Publisher($transport); $channel = new Channel('channel_one'); $message = new PublishMessage($channel, 'Hey there, im a message'); $publisher->publish($message); }
public function testMultipleSend() { $transportMock = $this->getMockBuilder('TrafficCophp\\Network\\SocketTransport')->setConstructorArgs(array('127.0.0.1', 1337))->getMock(); $transportMock->expects($this->atLeastOnce())->method('send'); $publisher = new Publisher($transportMock); for ($i = 0; $i < 3; $i++) { $messageMock = $this->getMockBuilder('TrafficCophp\\Message\\PublishMessage')->disableOriginalConstructor()->getMock(); $publisher->publish($messageMock); } }
<?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']); $publisher = new Publisher($transport); $channel = new Channel('channel_one'); $message = new PublishMessage($channel, 'Hey there, im a message'); $publisher->publish($message);
public function publish($channel, $message) { $this->publisher->publish(new PublishMessage(new Channel($channel), $message)); }