File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -140,4 +140,9 @@ Or set a default exception::
140
140
}
141
141
}
142
142
143
+
144
+ .. hint ::
145
+
146
+ If you're using the :doc: `/integrations/symfony-bundle `, the mock client is available as a service with ``httplug.client.mock `` id.
147
+
143
148
.. include :: includes/further-reading-async.inc
Original file line number Diff line number Diff line change @@ -205,6 +205,7 @@ services are:
205
205
* ``httplug.factory.guzzle6 ``
206
206
* ``httplug.factory.react ``
207
207
* ``httplug.factory.socket ``
208
+ * ``httplug.factory.mock `` (Install ``php-http/mock-client `` first)
208
209
209
210
Plugins
210
211
```````
@@ -342,6 +343,34 @@ The only steps they need is ``require`` one of the adapter implementations in
342
343
their projects ``composer.json `` and instantiating the ``HttplugBundle `` in
343
344
their kernel.
344
345
346
+ Mock Responses In Functional Tests
347
+ ``````````````````````````````````
348
+
349
+ First thing to do is add the :doc: `php-http/mock-client </clients/mock-client >` to your ``require-dev `` section.
350
+ Then, use the mock client factory in your test environment configuration:
351
+
352
+ .. code-block :: yaml
353
+
354
+ # config_test.yml
355
+ httplug :
356
+ clients :
357
+ my_awesome_client :
358
+ factory : ' httplug.factory.mock' # replace factory
359
+
360
+ To mock a response in your tests, do:
361
+
362
+ .. code-block :: php
363
+
364
+ // SomeWebTestCase.php
365
+ $client = static::createClient();
366
+
367
+ // If your test has the client (BrowserKit) make multiple requests, you need to disable reboot as the kernel is rebooted on each request.
368
+ // $client->disableReboot();
369
+
370
+ $response = $this->createMock('Psr\Http\Message\ResponseInterface');
371
+ $response->method('getBody')->willReturn(/* Psr\Http\Message\Interface instance containing expected response content. */);
372
+ $client->getContainer()->get('httplug.client.mock')->addResponse($response);
373
+
345
374
.. |clearfloat | raw :: html
346
375
347
376
<div style="clear:left"></div>
You can’t perform that action at this time.
0 commit comments