@@ -507,6 +507,8 @@ The only steps they need is ``require`` one of the adapter implementations in
507
507
their projects ``composer.json `` and instantiating the ``HttplugBundle `` in
508
508
their kernel.
509
509
510
+ .. _symfony-functional-tests :
511
+
510
512
Mock Responses In Functional Tests
511
513
``````````````````````````````````
512
514
@@ -522,8 +524,13 @@ Then, use the mock client factory in your test environment configuration:
522
524
factory : ' httplug.factory.mock' # replace factory
523
525
524
526
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.
527
534
528
535
To mock a response in your tests, do:
529
536
@@ -539,6 +546,22 @@ To mock a response in your tests, do:
539
546
$response->method('getBody')->willReturn(/* Psr\Http\Message\Interface instance containing expected response content. */);
540
547
$client->getContainer()->get('httplug.clients.my_awesome_backend.client')->addResponse($response);
541
548
549
+ .. hint ::
550
+
551
+ If you do not specify the factory in your configuration, you can directly
552
+ overwrite the httplug services:
553
+
554
+ # config/services_test.yaml
555
+ services:
556
+ # overwrite the http clients for mocking
557
+ httplug.client.my_awesome_backend:
558
+ class: Http\M ock\C lient
559
+ public: true
560
+
561
+ With this method, the plugin client is not applied. However, if you
562
+ configure a decorator, your mock client will still be decorated and the
563
+ mock available as service ``...<decorator>.inner ``.
564
+
542
565
Read more on how the mock client works in the :doc: `mock client documentation </clients/mock-client >`.
543
566
544
567
.. |clearfloat | raw :: html
0 commit comments