@@ -1391,18 +1391,20 @@ Testing
1391
1391
-------
1392
1392
1393
1393
This component includes the ``MockHttpClient `` and ``MockResponse `` classes to
1394
- use them in tests that shouldn't make actual HTTP requests. Such tests can be
1395
- useful, as they are faster and consistent due to not being dependant on
1396
- external service the request would be sent to. In result there is no need to
1397
- worry about the service being online or the request changing some state,
1398
- for example deleting a resource.
1394
+ use in tests that shouldn't make actual HTTP requests. Such tests can be
1395
+ useful, as they will run faster and produce consistent results, since they're
1396
+ not dependant on an external service. By not making actual HTTP requests there
1397
+ is no need to worry about the service being online or the request changing
1398
+ state, for example deleting a resource.
1399
1399
1400
1400
``MockHttpClient `` implements the ``HttpClientInterface ``, just like any actual
1401
- HTTP client in this component. You can use the interface to accept real client
1402
- in your code, while replacing it with ``MockHttpClient `` in the test.
1401
+ HTTP client in this component. When you typehint with ``HttpClientInterface ``
1402
+ your code will accept the real client outside tests, while replacing it with
1403
+ ``MockHttpClient `` in the test.
1403
1404
1404
1405
When the ``request `` method is used on ``MockHttpClient ``, it will respond with
1405
- supplied ``MockResponse ``. There are few ways to use it, as described below.
1406
+ the supplied ``MockResponse ``. There are a few ways to use it, as described
1407
+ below.
1406
1408
1407
1409
HTTP Client and Responses
1408
1410
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1468,10 +1470,11 @@ Testing Request Data
1468
1470
~~~~~~~~~~~~~~~~~~~~
1469
1471
1470
1472
The examples above describe how to return desired response. What if you wanted
1471
- to also test the request itself? ``MockResponse `` comes with helper methods:
1473
+ to also test the request itself? ``MockResponse `` comes with a few helper
1474
+ methods:
1472
1475
1473
- * ``getRequestMethod() `` - returns HTTP method
1474
- * ``getRequestUrl() `` - returns URL the request would be sent to
1476
+ * ``getRequestMethod() `` - returns the HTTP method
1477
+ * ``getRequestUrl() `` - returns the URL the request would be sent to
1475
1478
* ``getRequestOptions() `` - returns an array containing other information about
1476
1479
the request such as headers, query parameters, body content etc.
1477
1480
@@ -1500,7 +1503,7 @@ Example
1500
1503
~~~~~~~
1501
1504
1502
1505
The following standalone example demonstrates a way to use HTTP client and
1503
- test it in real application::
1506
+ test it in a real application::
1504
1507
1505
1508
// ExternalArticleService.php
1506
1509
use Symfony\Contracts\HttpClient\HttpClientInterface;
0 commit comments