コード例 #1
0
ファイル: ConnectionTest.php プロジェクト: Rudi9719/stein-syn
 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
ファイル: CallTest.php プロジェクト: Rudi9719/stein-syn
 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
ファイル: PublishTest.php プロジェクト: Rudi9719/stein-syn
 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']);
 }
コード例 #4
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);
 }
コード例 #5
0
ファイル: EventTest.php プロジェクト: Rudi9719/stein-syn
 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']);
 }