Open patrickbussmann opened 4 years ago
its a bit complicated
Indeed! 😅
The reason there aren't any PHPUnit tests for the WebSocket server is because that's pretty well covered by the Autobahn Testsuite.
Okay. So for now I can use both. But for me its more pretty to focus on one test type now.
Maybe you can help me with small thing - but for my its very big. I was able to set up the server in theory - with the IoServer test case. (instead websockets)
public function setUp() {
// $this->markTestSkipped();
self::bootKernel();
$this->_app = $this->getMockBuilder(WsServer::class)
->setConstructorArgs([
self::$container->get(ChatServer::class)
])
->getMock();
$this->_app = new WsServer(self::$container->get(ChatServer::class));
$decorator = $this->getDecoratorClassString();
$this->_serv = IoServer::factory(new $decorator($this->_app), 12312);
$this->_serv->run();
$this->_conn = $this->getMockBuilder('\Ratchet\ConnectionInterface')->getMock();
$this->doOpen($this->_conn);
$this->_conn->httpHeadersReceived = true;
}
And then my test is always failing.
public function testMessage() {
// $headers = "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n";
// $this->_conn->httpHeadersReceived = false;
// $this->_serv->onMessage($this->_conn, $headers);
$message = "Hello World!";
// $this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $message);
$this->_serv->onOpen($this->_conn);
$this->_serv->onMessage($this->_conn, 'invalid json');
$this->assertTrue('asd' == true);
// sleep(20);
}
I never got a connected client. Maybe because I place the ticks wrong?
But I go to Autobahn then.
I find the IoSocket Server tests here: https://github.com/ratchetphp/Ratchet/tree/master/tests/unit/Server
But there are no WebSocket Server tests. So I tried to work on but its a bit complicated.
So this is the test case from the original test file above. (tests/unit/Server)
Original constructor:
And when I change something:
Then the server can start (last line outcommented)
And with JavaScript I'm able to connect.
But with my test method its not working.
Its hanging in an endless loop. Without
->run()
its not getting a connection.Do someone know how to test WebSockets on Ratchet? ☺