diff --git a/http_client.rst b/http_client.rst index 834ada0b10a..6254d816efe 100644 --- a/http_client.rst +++ b/http_client.rst @@ -1678,6 +1678,23 @@ responses dynamically when it's called:: $client = new MockHttpClient($callback); $response = $client->request('...'); // calls $callback to get the response +.. tip:: + + Instead of using the first argument, you can also set the (list of) + responses or callbacks using the ``setResponseFactory()`` method:: + + $responses = [ + new MockResponse($body1, $info1), + new MockResponse($body2, $info2), + ]; + + $client = new MockHttpClient(); + $client->setResponseFactory($responses); + + .. versionadded:: 5.4 + + The ``setResponseFactory()`` method was introduced in Symfony 5.4. + If you need to test responses with HTTP status codes different than 200, define the ``http_code`` option::