title: Websocket Testing [Functional]
body: <p>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:</p>
  
  <ol>
  <li>Create a (ratchet) client in phpunit</li>
  <li>Connect to ws url (e.g. client->connect(host, port, ...)</li>
  <li>ping websocket / send / receive some messages (call methods of client, e.g. client->push(..)..)</li>
  </ol>
  
  <p>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)</p>
  
  <p>As an example, within a functional test for a feature, I could do the following:</p>
  
  <pre><code>$client = static::createClient();
  $client-&gt;request('GET', '/book/3', array(), array(), array('HTTP_X-Requested-With' =&gt; 'XMLHttpRequest'));
  $response = $client-&gt;getResponse();
  $this-&gt;assertEquals(
      440,
      $response-&gt;getStatusCode()
  );
  </code></pre>
  
  <p>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?</p>