Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clients/mock-client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,9 @@ Or set a default exception::
}
}


.. hint::

If you're using the :doc:`/integrations/symfony-bundle`, the mock client is available as a service with ``httplug.client.mock`` id.

.. include:: includes/further-reading-async.inc
29 changes: 29 additions & 0 deletions integrations/symfony-bundle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ services are:
* ``httplug.factory.guzzle6``
* ``httplug.factory.react``
* ``httplug.factory.socket``
* ``httplug.factory.mock`` (Install ``php-http/mock-client`` first)

Plugins
```````
Expand Down Expand Up @@ -342,6 +343,34 @@ The only steps they need is ``require`` one of the adapter implementations in
their projects ``composer.json`` and instantiating the ``HttplugBundle`` in
their kernel.

Mock Responses In Functional Tests
``````````````````````````````````

First thing to do is add the :doc:`php-http/mock-client </clients/mock-client>` to your ``require-dev`` section.
Then, use the mock client factory in your test environment configuration:

.. code-block:: yaml

# config_test.yml
httplug:
clients:
my_awesome_client:
factory: 'httplug.factory.mock' # replace factory

To mock a response in your tests, do:

.. code-block:: php

// SomeWebTestCase.php
$client = static::createClient();

// If your test has the client (BrowserKit) make multiple requests, you need to disable reboot as the kernel is rebooted on each request.
// $client->disableReboot();

$response = $this->createMock('Psr\Http\Message\ResponseInterface');
$response->method('getBody')->willReturn(/* Psr\Http\Message\Interface instance containing expected response content. */);
$client->getContainer()->get('httplug.client.mock')->addResponse($response);

.. |clearfloat| raw:: html

<div style="clear:left"></div>
Expand Down