Skip to content

Commit c2d063b

Browse files
authored
Merge pull request #307 from php-http/dbu-patch-1
clarify mocking in symfony
2 parents 6f259c1 + ab8e5f0 commit c2d063b

File tree

5 files changed

+28
-64
lines changed

5 files changed

+28
-64
lines changed

_static/highlight.css

-59
This file was deleted.

clients/mock-client.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ Or pass a callable, and return a response or exception based on the request::
226226

227227
.. hint::
228228

229-
If you're using the :doc:`/integrations/symfony-bundle`, the mock client is available as a service with ``httplug.client.mock`` id.
229+
If you're using the :doc:`/integrations/symfony-bundle`, the mock client is
230+
available as a service with ``httplug.client.mock`` id.
231+
232+
See :ref:`symfony-functional-tests` for more on how to use the mock client in Symfony.
230233

231234
.. include:: includes/further-reading-async.inc

conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159

160160
html_css_files = [
161161
'custom.css',
162-
'highlight.css',
163162
]
164163

165164
# Add any extra paths that contain custom files (such as robots.txt or

integrations/symfony-bundle.rst

+23-2
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ The only steps they need is ``require`` one of the adapter implementations in
507507
their projects ``composer.json`` and instantiating the ``HttplugBundle`` in
508508
their kernel.
509509

510+
.. _symfony-functional-tests:
511+
510512
Mock Responses In Functional Tests
511513
``````````````````````````````````
512514

@@ -522,8 +524,13 @@ Then, use the mock client factory in your test environment configuration:
522524
factory: 'httplug.factory.mock' # replace factory
523525
524526
The client is always wrapped into a plugin client. Therefore you need to access
525-
the inner client, which has `.client` appended. For the example above, the full
526-
name is `httplug.clients.my_awesome_backend.client`.
527+
the inner client to get the mock client. It is available in the container with
528+
the suffix ``.inner``. For the example above, the full name is
529+
``httplug.clients.my_awesome_backend.inner``.
530+
531+
If you enable a decorator like ``http_methods_client: true``, the actual mock
532+
client will be at ``httplug.client.my_awesome_backend.http_methods.inner``. Use
533+
the ``container:debug`` command to make sure you grab the correct service.
527534

528535
To mock a response in your tests, do:
529536

@@ -539,6 +546,20 @@ To mock a response in your tests, do:
539546
$response->method('getBody')->willReturn(/* Psr\Http\Message\Interface instance containing expected response content. */);
540547
$client->getContainer()->get('httplug.clients.my_awesome_backend.client')->addResponse($response);
541548
549+
If you do not specify the factory in your configuration, you can also directly
550+
overwrite the httplug services:
551+
552+
# config/services_test.yaml
553+
services:
554+
# overwrite the http clients for mocking
555+
httplug.client.my_awesome_backend:
556+
class: Http\Mock\Client
557+
public: true
558+
559+
With this method, the plugin client is not applied. However, if you configure a
560+
decorator, your mock client will still be decorated and the mock available as
561+
service ``...<decorator>.inner``.
562+
542563
Read more on how the mock client works in the :doc:`mock client documentation </clients/mock-client>`.
543564

544565
.. |clearfloat| raw:: html

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
git+https://github.com/fabpot/sphinx-php.git#egg=sphinx-php
22
sphinx~=4.2.0
3-
sphinx-rtd-theme==1.0.0
3+
sphinx-rtd-theme==1.2.0
44
sphinxcontrib-spelling~=7.2.0
55
pyenchant
66
docutils==0.17

0 commit comments

Comments
 (0)