コード例 #1
0
 public function testPublish()
 {
     $loop = $this->loop;
     $client = new Client($loop, $this->host, $this->port, $this->path);
     $published = null;
     $this->server->setOnPublishCallback(function (ConnectionInterface $conn, $topic, $event) use(&$published, $loop) {
         /** @var \Ratchet\Wamp\Topic $topic */
         $published = array('topic' => $topic->getId(), 'message' => $event);
         $loop->stop();
     });
     $response = null;
     $client->setOnWelcomeCallback(function (Client $conn, $data) use(&$response, $loop) {
         $conn->publish('mytopic', 'my_message');
     });
     $loop->run();
     $this->assertEquals('mytopic', $published['topic']);
     $this->assertEquals('my_message', $published['message']);
 }
コード例 #2
0
 public function testUnSubscription()
 {
     $loop = $this->loop;
     $client = new Client($loop, $this->host, $this->port, $this->path);
     $unsubscribed = null;
     $this->server->setOnUnSubscribeCallback(function (ConnectionInterface $conn, $topic) use(&$unsubscribed, $loop) {
         /** @var \Ratchet\Wamp\Topic $topic */
         $unsubscribed = $topic->getId();
         $loop->stop();
     });
     $this->server->setOnSubscribeCallback(function (ConnectionInterface $conn, $topic) use($client) {
         $client->unsubscribe('this_is_my_new_topic');
     });
     $client->setOnWelcomeCallback(function (Client $conn, $data) use(&$response, $loop) {
         $conn->subscribe('this_is_my_new_topic');
     });
     $loop->run();
     $this->assertEquals('this_is_my_new_topic', $unsubscribed);
 }
コード例 #3
0
 public function testEvent()
 {
     $loop = $this->loop;
     $client = new Client($loop, $this->host, $this->port, $this->path);
     $server = $this->server;
     $this->server->setOnSubscribeCallback(function (ConnectionInterface $conn, $topic) use($server) {
         /** @var \Ratchet\Wamp\Topic $topic */
         $server->broadcast($topic->getId(), 'this is my message');
     });
     $response = null;
     $client->setOnEventCallback(function (Client $conn, $topic, $data) use(&$response, $loop) {
         $response = array('topic' => $topic, 'message' => $data);
         $loop->stop();
     });
     $client->setOnWelcomeCallback(function (Client $conn, $data) {
         $conn->subscribe('test_topic');
     });
     $loop->run();
     $this->assertEquals('test_topic', $response['topic']);
     $this->assertEquals('this is my message', $response['message']);
 }
コード例 #4
0
 public function tearDown()
 {
     $this->server->close();
 }