Skip to content

clarify mocking in symfony #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2023
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
59 changes: 0 additions & 59 deletions _static/highlight.css

This file was deleted.

5 changes: 4 additions & 1 deletion clients/mock-client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ Or pass a callable, and return a response or exception based on the request::

.. hint::

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

See :ref:`symfony-functional-tests` for more on how to use the mock client in Symfony.

.. include:: includes/further-reading-async.inc
1 change: 0 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@

html_css_files = [
'custom.css',
'highlight.css',
]

# Add any extra paths that contain custom files (such as robots.txt or
Expand Down
25 changes: 23 additions & 2 deletions integrations/symfony-bundle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ The only steps they need is ``require`` one of the adapter implementations in
their projects ``composer.json`` and instantiating the ``HttplugBundle`` in
their kernel.

.. _symfony-functional-tests:

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

Expand All @@ -522,8 +524,13 @@ Then, use the mock client factory in your test environment configuration:
factory: 'httplug.factory.mock' # replace factory

The client is always wrapped into a plugin client. Therefore you need to access
the inner client, which has `.client` appended. For the example above, the full
name is `httplug.clients.my_awesome_backend.client`.
the inner client to get the mock client. It is available in the container with
the suffix ``.inner``. For the example above, the full name is
``httplug.clients.my_awesome_backend.inner``.

If you enable a decorator like ``http_methods_client: true``, the actual mock
client will be at ``httplug.client.my_awesome_backend.http_methods.inner``. Use
the ``container:debug`` command to make sure you grab the correct service.

To mock a response in your tests, do:

Expand All @@ -539,6 +546,20 @@ To mock a response in your tests, do:
$response->method('getBody')->willReturn(/* Psr\Http\Message\Interface instance containing expected response content. */);
$client->getContainer()->get('httplug.clients.my_awesome_backend.client')->addResponse($response);

If you do not specify the factory in your configuration, you can also directly
overwrite the httplug services:

# config/services_test.yaml
services:
# overwrite the http clients for mocking
httplug.client.my_awesome_backend:
class: Http\Mock\Client
public: true

With this method, the plugin client is not applied. However, if you configure a
decorator, your mock client will still be decorated and the mock available as
service ``...<decorator>.inner``.

Read more on how the mock client works in the :doc:`mock client documentation </clients/mock-client>`.

.. |clearfloat| raw:: html
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
git+https://github.com/fabpot/sphinx-php.git#egg=sphinx-php
sphinx~=4.2.0
sphinx-rtd-theme==1.0.0
sphinx-rtd-theme==1.2.0
sphinxcontrib-spelling~=7.2.0
pyenchant
docutils==0.17