5
RingPHP tests client handlers using `PHPUnit <https://phpunit.de/>`_ and a
6
built-in node.js web server.
11
First, install the dependencies using `Composer <https://getcomposer.org>`_.
15
Next, run the unit tests using ``Make``.
19
The tests are also run on Travis-CI on each commit: https://travis-ci.org/guzzle/guzzle-ring
24
Testing client handlers usually involves actually sending HTTP requests.
25
RingPHP provides a node.js web server that returns canned responses and
26
keep a list of the requests that have been received. The server can then
27
be queried to get a list of the requests that were sent by the client so that
28
you can ensure that the client serialized and transferred requests as intended.
30
The server keeps a list of queued responses and returns responses that are
31
popped off of the queue as HTTP requests are received. When there are not
32
more responses to serve, the server returns a 500 error response.
34
The test server uses the ``GuzzleHttp\Tests\Ring\Client\Server`` class to
39
use GuzzleHttp\Ring\Client\StreamHandler;
40
use GuzzleHttp\Tests\Ring\Client\Server;
42
// First return a 200 followed by a 404 response.
48
$handler = new StreamHandler();
50
$response = $handler([
51
'http_method' => 'GET',
52
'headers' => ['host' => [Server::$host]],
56
assert(200 == $response['status']);
58
$response = $handler([
59
'http_method' => 'HEAD',
60
'headers' => ['host' => [Server::$host]],
64
assert(404 == $response['status']);
66
After requests have been sent, you can get a list of the requests as they
67
were sent over the wire to ensure they were sent correctly.
71
$received = Server::received();
73
assert('GET' == $received[0]['http_method']);
74
assert('HEAD' == $received[1]['http_method']);