Skip to content

Commit 90b157d

Browse files
[HttpClient] Mention list of callbacks for MockHttpClient
1 parent 1c33f40 commit 90b157d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

http_client.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,33 @@ responses dynamically when it's called::
17581758
$client = new MockHttpClient($callback);
17591759
$response = $client->request('...'); // calls $callback to get the response
17601760

1761+
You can also pass a list of callbacks if you need to perform specific
1762+
assertions on the request before returning the mocked response::
1763+
1764+
$expectedRequests = [
1765+
function ($method, $url, $options) {
1766+
$this->assertSame('GET', $method);
1767+
$this->assertSame('https://example.com/api/v1/customer', $url);
1768+
1769+
return new MockResponse('...');
1770+
},
1771+
function ($method, $url, $options) {
1772+
$this->assertSame('POST', $method);
1773+
$this->assertSame('https://example.com/api/v1/customer/1/products', $url);
1774+
1775+
return new MockResponse('...');
1776+
},
1777+
];
1778+
1779+
$client = new MockHttpClient($expectedRequest);
1780+
1781+
// ...
1782+
1783+
.. versionadded:: 5.1
1784+
1785+
Passing a list of callbacks to the ``MockHttpClient`` was introduced
1786+
in Symfony 5.1.
1787+
17611788
.. tip::
17621789

17631790
Instead of using the first argument, you can also set the (list of)

0 commit comments

Comments
 (0)