I am using Ratchet for websockets in PHP. I was able to write unit (phpspec) and acceptance tests (behat) for websockets but I cannot find a way on how to test the connection to the websocket server by using a functional phpunit test.. I think a test, which checks if the connection is up and running, would be very important. I thought of something like the following:
- Create a (ratchet) client in phpunit
- Connect to ws url (e.g. client->connect(host, port, ...)
- ping websocket / send / receive some messages (call methods of client, e.g. client->push(..)..)
The problem is, that I don't know which class is responsible for establishing the connection (creating a client which can request the websocket) in Ratchet and how a test would then look like. How can I create a Ratchet Client in order to be able to connect and request a websocket in phpunit functional test? (similar to e.g. a webclient within a standard phpunit functional test)
As an example, within a functional test for a feature, I could do the following:
$client = static::createClient();
$client->request('GET', '/book/3', array(), array(), array('HTTP_X-Requested-With' => 'XMLHttpRequest'));
$response = $client->getResponse();
$this->assertEquals(
440,
$response->getStatusCode()
);
Or e.g. create an authenticated client instead of an anonymous. How would it be possible, to "translate" this functional test into a ratchet websocket one?