You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: http_client.rst
+12-8Lines changed: 12 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -2196,11 +2196,15 @@ test it in a real application::
2196
2196
}
2197
2197
}
2198
2198
2199
-
Testing using HAR files
2199
+
Testing Using HAR Files
2200
2200
~~~~~~~~~~~~~~~~~~~~~~~
2201
2201
2202
-
The previous example can also be achieved using `HAR`_ files. You can export those files from all modern browsers (from the network tab) &
2203
-
HTTP Clients. First, do the HTTP request(s) you want to test in your favorite HTTP Client / Browser, then store generated ``.har`` file somewhere in your application::
2202
+
Modern browsers (via their network tab) and HTTP clients allow to export the
2203
+
information of one or more HTTP requests using the `HAR`_ (HTTP Archive) format.
2204
+
You can use those ``.har`` files to perform tests with Symfony's HTTP Client.
2205
+
2206
+
First, use a browser or HTTP client to perform the HTTP request(s) you want to
2207
+
test. Then, save that information as a ``.har`` file somewhere in your application::
2204
2208
2205
2209
// ExternalArticleServiceTest.php
2206
2210
use PHPUnit\Framework\TestCase;
@@ -2225,11 +2229,11 @@ HTTP Clients. First, do the HTTP request(s) you want to test in your favorite HT
2225
2229
}
2226
2230
}
2227
2231
2228
-
2229
-
If your service does multiple requests or if your `.har` file contains multiple request / response pairs,
2230
-
the :class:`Symfony\\Component\\HttpClient\\Test\\HarFileResponseFactory` will find the associated response based on
2231
-
the request method, url and body (if any). Note that **this doesn't work** if the request body or uri is random / always changing
2232
-
(if it contains current date or random UUID(s) for example).
2232
+
If your service performs multiple requests or if your ``.har`` file contains multiple
2233
+
request/response pairs, the :class:`Symfony\\Component\\HttpClient\\Test\\HarFileResponseFactory`
2234
+
will find the associated response based on the request method, URL and body (if any).
2235
+
Note that **this won't work** if the request body or URI is random / always
2236
+
changing (e.g. if it contains current date or random UUIDs).
0 commit comments