Skip to content

[HttpClient] HttpClientInterface::setResponseFactory method #15883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down