File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1758,6 +1758,33 @@ responses dynamically when it's called::
1758
1758
$client = new MockHttpClient($callback);
1759
1759
$response = $client->request('...'); // calls $callback to get the response
1760
1760
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
+
1761
1788
.. tip ::
1762
1789
1763
1790
Instead of using the first argument, you can also set the (list of)
You can’t perform that action at this time.
0 commit comments