From 0af6beb157cb361e72595ff7531eee61f84e0295 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 11 May 2023 09:50:14 +0200 Subject: [PATCH 1/2] clarify mocking in symfony --- clients/mock-client.rst | 5 ++++- integrations/symfony-bundle.rst | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/clients/mock-client.rst b/clients/mock-client.rst index c4b9faf..5f7b927 100644 --- a/clients/mock-client.rst +++ b/clients/mock-client.rst @@ -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 diff --git a/integrations/symfony-bundle.rst b/integrations/symfony-bundle.rst index 3a81efa..72e0407 100644 --- a/integrations/symfony-bundle.rst +++ b/integrations/symfony-bundle.rst @@ -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 `````````````````````````````````` @@ -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: @@ -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 ``....inner``. + Read more on how the mock client works in the :doc:`mock client documentation `. .. |clearfloat| raw:: html From ab8e5f01a0a141d92da4a843e13bc54f36a951f0 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 11 May 2023 10:08:40 +0200 Subject: [PATCH 2/2] use current theme and drop custom highlight as it collides with default css --- _static/highlight.css | 59 ------------------------------------------- conf.py | 1 - requirements.txt | 2 +- 3 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 _static/highlight.css diff --git a/_static/highlight.css b/_static/highlight.css deleted file mode 100644 index 27d7927..0000000 --- a/_static/highlight.css +++ /dev/null @@ -1,59 +0,0 @@ -div.highlight { - background-color: #343131 !important; -} - -div.highlight pre { - border: none; - color: white !important; -} - -div.highlight pre span.n, -div.highlight pre span.na, -div.highlight pre span.nb, -div.highlight pre span.nc, -div.highlight pre span.nf, -div.highlight pre span.nx, -div.highlight pre span.kn { - color: white; -} - -div.highlight pre span.nv { - color: #6ab0de -} - -div.highlight pre span.k, div.highlight pre span.o { - color: #ff8400; -} - -div.highlight pre span.mi, -div.highlight pre span.s, -div.highlight pre span.s1, -div.highlight pre span.s2, -div.highlight pre span.sr { - color: #56db3a; -} - -div.highlight pre span.hll { - background-color: #848484; -} - -div.highlight pre span.hll span.c1 { - color: #d8d8d8; -} - -div.highlight pre span.p { - color: #b3b3b3; -} - -table.highlighttable td { - padding: 0; -} - -table.highlighttable td div.linenodiv { - text-align: right; - width: 38px; -} - -div.highlight-json pre span.nt { - color: cornsilk; -} diff --git a/conf.py b/conf.py index c7fde6f..8498f1b 100644 --- a/conf.py +++ b/conf.py @@ -159,7 +159,6 @@ html_css_files = [ 'custom.css', - 'highlight.css', ] # Add any extra paths that contain custom files (such as robots.txt or diff --git a/requirements.txt b/requirements.txt index f9bca84..7a58018 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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