Exemple #1
0
 private function runTestWith($method, $url, array $headers = [], $protocolVersion = '1.0', $body)
 {
     $router = $this->createTestRouter();
     $wampPost = new WampPost("test_realm", \EventLoop\getLoop(), "127.0.0.1", 18181);
     $opened = false;
     $wampPost->on('open', function (ClientSession $session) use(&$opened, $router) {
         $opened = true;
         $session->register("procedure.that.errors", function () {
             throw new WampErrorException("my.custom.error", [4, 5, 6], (object) ["x" => "y"], (object) ["y" => "z"]);
         });
         $this->_testTopicEvents = [];
         // this subscription is here to test that options are working ("exclude_me")
         $session->subscribe("wamppost.tests.nonexclude.topic", function ($args, $argsKw, $details, $pubId) {
             $event = new EventMessage(0, $pubId, $details, $args, $argsKw, "wamppost.tests.nonexclude.topic");
             $this->_testTopicEvents[] = $event;
         });
     });
     $router->addInternalClient($wampPost);
     $response = null;
     $responseBody = null;
     \EventLoop\addTimer(0, function () use(&$response, &$responseBody, $method, $url, $headers, $protocolVersion, $body) {
         $this->makeHttpRequest($method, $url, $headers, $protocolVersion, $body)->then(function ($ret) use(&$response, &$responseBody) {
             list($response, $responseBody) = $ret;
             $this->stopRouter();
         });
     });
     $this->startRouterWithTimeout(5);
     $this->assertEmpty($this->expectedMessages);
     $this->assertNotNull($response);
     $this->assertNotNull($responseBody);
     $this->assertTrue($opened);
     return [$response, $responseBody, $this->recordedEvents];
 }
Exemple #2
0
 protected function startRouterWithTimeout($timeout)
 {
     $this->assertNull($this->currentTimer);
     $this->currentTimer = \EventLoop\addTimer($timeout, function () {
         \EventLoop\getLoop()->stop();
         $this->fail("Router timeout exceeded");
     });
     $this->router->start();
 }
Exemple #3
0
<?php

require_once __DIR__ . '/../bootstrap.php';
if ($argc > 1 && is_numeric($argv[1])) {
    echo "Setting test server to stop in " . $argv[1] . " seconds.\n";
    \EventLoop\addTimer($argv[1], function () {
        exit;
    });
}
$server = new \Rx\Websocket\Server("127.0.0.1", 9001, true);
$server->subscribe(new \Rx\Observer\CallbackObserver(function (\Rx\Websocket\MessageSubject $ms) {
    $ms->subscribe($ms);
}));