~tcuthbert/wordpress/openstack-objectstorage-k8s

« back to all changes in this revision

Viewing changes to vendor/guzzlehttp/ringphp/docs/testing.rst

  • Committer: Thomas Cuthbert
  • Date: 2020-04-23 05:22:45 UTC
  • Revision ID: thomas.cuthbert@canonical.com-20200423052245-1jxao3mw31w435js
[,r=trivial] bionic composer vendor update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=======
 
2
Testing
 
3
=======
 
4
 
 
5
RingPHP tests client handlers using `PHPUnit <https://phpunit.de/>`_ and a
 
6
built-in node.js web server.
 
7
 
 
8
Running Tests
 
9
-------------
 
10
 
 
11
First, install the dependencies using `Composer <https://getcomposer.org>`_.
 
12
 
 
13
    composer.phar install
 
14
 
 
15
Next, run the unit tests using ``Make``.
 
16
 
 
17
    make test
 
18
 
 
19
The tests are also run on Travis-CI on each commit: https://travis-ci.org/guzzle/guzzle-ring
 
20
 
 
21
Test Server
 
22
-----------
 
23
 
 
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.
 
29
 
 
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.
 
33
 
 
34
The test server uses the ``GuzzleHttp\Tests\Ring\Client\Server`` class to
 
35
control the server.
 
36
 
 
37
.. code-block:: php
 
38
 
 
39
    use GuzzleHttp\Ring\Client\StreamHandler;
 
40
    use GuzzleHttp\Tests\Ring\Client\Server;
 
41
 
 
42
    // First return a 200 followed by a 404 response.
 
43
    Server::enqueue([
 
44
        ['status' => 200],
 
45
        ['status' => 404]
 
46
    ]);
 
47
 
 
48
    $handler = new StreamHandler();
 
49
 
 
50
    $response = $handler([
 
51
        'http_method' => 'GET',
 
52
        'headers'     => ['host' => [Server::$host]],
 
53
        'uri'         => '/'
 
54
    ]);
 
55
 
 
56
    assert(200 == $response['status']);
 
57
 
 
58
    $response = $handler([
 
59
        'http_method' => 'HEAD',
 
60
        'headers'     => ['host' => [Server::$host]],
 
61
        'uri'         => '/'
 
62
    ]);
 
63
 
 
64
    assert(404 == $response['status']);
 
65
 
 
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.
 
68
 
 
69
.. code-block:: php
 
70
 
 
71
    $received = Server::received();
 
72
 
 
73
    assert('GET' == $received[0]['http_method']);
 
74
    assert('HEAD' == $received[1]['http_method']);