コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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();
 }
コード例 #5
0
 public function testGetChannelNames()
 {
     $chn = new Channel('one');
     $this->channels->add($chn);
     $this->assertEquals(['one'], $this->channels->getChannelNames());
 }