Skip to content

Commit 47a1572

Browse files
committed
feature #15883 [HttpClient] HttpClientInterface::setResponseFactory method (greeflas)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpClient] HttpClientInterface::setResponseFactory method <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `5.x` for features of unreleased versions). --> Commits ------- 76bd5fb [HttpClient] HttpClientInterface::setResponseFactory method
2 parents 8c6086b + 76bd5fb commit 47a1572

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

http_client.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,23 @@ responses dynamically when it's called::
17091709
$client = new MockHttpClient($callback);
17101710
$response = $client->request('...'); // calls $callback to get the response
17111711

1712+
.. tip::
1713+
1714+
Instead of using the first argument, you can also set the (list of)
1715+
responses or callbacks using the ``setResponseFactory()`` method::
1716+
1717+
$responses = [
1718+
new MockResponse($body1, $info1),
1719+
new MockResponse($body2, $info2),
1720+
];
1721+
1722+
$client = new MockHttpClient();
1723+
$client->setResponseFactory($responses);
1724+
1725+
.. versionadded:: 5.4
1726+
1727+
The ``setResponseFactory()`` method was introduced in Symfony 5.4.
1728+
17121729
If you need to test responses with HTTP status codes different than 200,
17131730
define the ``http_code`` option::
17141731

0 commit comments

Comments
 (0)