public function testConnection()
 {
     $loop = $this->loop;
     $client = new Client($loop, $this->host, $this->port, $this->path);
     $response = null;
     $client->setOnWelcomeCallback(function (Client $conn, array $data) use(&$response, $loop) {
         $response = $data;
         $loop->stop();
     });
     $loop->run();
     $this->assertNotNull($response);
 }
예제 #2
0
 public function testCall()
 {
     $loop = $this->loop;
     $client = new Client($loop, $this->host, $this->port, $this->path);
     $response = null;
     $client->setOnWelcomeCallback(function (Client $conn, $data) use(&$response, $loop) {
         $conn->call('mymethod', array('my_value'), function ($data) use(&$response, $loop) {
             $response = $data;
             $loop->stop();
         });
     });
     $loop->run();
     $this->assertEquals('my_value', $response[0]);
 }
예제 #3
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']);
 }
 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);
 }
예제 #5
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']);
 }