Skip to content

Commit 20a5716

Browse files
committed
feature #19306 [HttpClient] Add JsonMockResponse::fromFile() and MockResponse::fromFile() shortcuts (alexandre-daubois)
This PR was merged into the 7.1 branch. Discussion ---------- [HttpClient] Add `JsonMockResponse::fromFile()` and `MockResponse::fromFile()` shortcuts Fix #19303 Commits ------- 6bd4948 [HttpClient] Add `JsonMockResponse::fromFile()` and `MockResponse::fromFile()` shortcuts
2 parents 0b70c22 + 6bd4948 commit 20a5716

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
@@ -1905,6 +1905,20 @@ in order when requests are made::
19051905
$response1 = $client->request('...'); // returns $responses[0]
19061906
$response2 = $client->request('...'); // returns $responses[1]
19071907

1908+
It is also possible to create a
1909+
:class:`Symfony\\Component\\HttpClient\\Response\\MockResponse` directly
1910+
from a file, which is particularly useful when storing your responses
1911+
snapshots in files::
1912+
1913+
use Symfony\Component\HttpClient\Response\MockResponse;
1914+
1915+
$response = MockResponse::fromFile('tests/fixtures/response.xml');
1916+
1917+
.. versionadded:: 7.1
1918+
1919+
The :method:`Symfony\\Component\\HttpClient\\Response\\MockResponse::fromFile`
1920+
method was introduced in Symfony 7.1.
1921+
19081922
Another way of using :class:`Symfony\\Component\\HttpClient\\MockHttpClient` is to
19091923
pass a callback that generates the responses dynamically when it's called::
19101924

@@ -2079,6 +2093,19 @@ You can use :class:`Symfony\\Component\\HttpClient\\Response\\JsonMockResponse`
20792093
'foo' => 'bar',
20802094
]);
20812095

2096+
Just like :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse`, you can
2097+
also create a :class:`Symfony\\Component\\HttpClient\\Response\\JsonMockResponse`
2098+
directly from a file::
2099+
2100+
use Symfony\Component\HttpClient\Response\JsonMockResponse;
2101+
2102+
$response = JsonMockResponse::fromFile('tests/fixtures/response.json');
2103+
2104+
.. versionadded:: 7.1
2105+
2106+
The :method:`Symfony\\Component\\HttpClient\\Response\\JsonMockResponse::fromFile`
2107+
method was introduced in Symfony 7.1.
2108+
20822109
Testing Request Data
20832110
~~~~~~~~~~~~~~~~~~~~
20842111

0 commit comments

Comments
 (0)