@@ -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,20 @@ 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
+ 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\M ock\C lient
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
+
542
563
Read more on how the mock client works in the :doc: `mock client documentation </clients/mock-client >`.
543
564
544
565
.. |clearfloat | raw :: html
0 commit comments