Testing API requests
Last updated
Was this helpful?
Last updated
Was this helpful?
When testing HTTP requests you need to create mock responses based on what would actually be returned from a real HTTP request. Symfony's HTTPClient has support for .
You can also use theMockResponseFromFile
class to generate a mock response easily from a file.
Allows you to load a mock request from file.
$filename (string)
File to load mock response from
Body file is loaded from {$filename}
The optional info file is loaded from {$filename}.info.php
and must contain the $info
variable (array). By default mock responses return a 200 status code which you can change by setting the $info
array.
The following code loads ./responses/api-test.json
and if it exists ./responses/api-test.json.info.php
to create a mock response.
http_code (int)
- the last HTTP response code
response_headers (array)
- an array of response headers
See for possible info, the most common are: