/** * @inheritdoc */ public function run(ConnectionInterface $from, \stdClass $package) { $channelName = $package->channel; if (!$this->channels->exists($channelName)) { $chn = new Channel($channelName); $this->channels->add($chn); } $this->channels->get($channelName)->addConnection($from); }
public function testSendsToConnectionsInChannel() { $chn = new Channel('my-channel'); $chn->addConnection($this->connection); $this->channels->add($chn); $package = (object) ['from' => 'Helmut', 'channel' => 'my-channel', 'message' => 'Hello World']; $this->command->run($this->connection, $package); $res = json_decode($this->packages[0]); $this->assertEquals('Hello World', $res->message); }
public function setUp() { parent::setUp(); $this->channels = new ChannelCollection(); $chn = new Channel('my-channel'); $this->channels->add($chn); $this->command = new LeaveChannelCommand($this->channels); $mock = $this->prophesize(ConnectionInterface::class); $mock->close()->willReturn(null); $mock->send(Argument::any())->willReturn($mock->reveal()); $this->connection = $mock->reveal(); $chn->addConnection($this->connection); }
public function setUp() { parent::setUp(); $this->channels = new ChannelCollection(); $this->channels->add(new Channel('my-channel')); $this->channels->add(new Channel('my-other-channel')); $this->command = new ListChannelsCommand($this->channels); $this->packages = []; $parent = $this; $mock = $this->prophesize(ConnectionInterface::class); $mock->close()->willReturn(null); $mock->send(Argument::any())->will(function ($args) use($parent) { $parent->packages[] = $args[0]; }); $this->connection = $mock->reveal(); }
public function testGetChannelNames() { $chn = new Channel('one'); $this->channels->add($chn); $this->assertEquals(['one'], $this->channels->getChannelNames()); }