HttpClientTrait
Define mock responses and have mocks automatically cleared.
Table of Contents
Methods
- cleanupMockResponses() : void
- Resets mocked responses
- mockClientDelete() : void
- Add a mock response for a DELETE request.
- mockClientGet() : void
- Add a mock response for a GET request.
- mockClientPatch() : void
- Add a mock response for a PATCH request.
- mockClientPost() : void
- Add a mock response for a POST request.
- mockClientPut() : void
- Add a mock response for a PUT request.
- newClientResponse() : Response
- Create a new response.
Methods
cleanupMockResponses()
Resets mocked responses
public
cleanupMockResponses() : void
Tags
mockClientDelete()
Add a mock response for a DELETE request.
public
mockClientDelete(string $url, Response $response[, array<string, mixed> $options = [] ]) : void
Parameters
- $url : string
-
The URL to mock
- $response : Response
-
The response for the mock.
- $options : array<string, mixed> = []
-
Additional options. See Client::addMockResponse()
mockClientGet()
Add a mock response for a GET request.
public
mockClientGet(string $url, Response $response[, array<string, mixed> $options = [] ]) : void
Parameters
- $url : string
-
The URL to mock
- $response : Response
-
The response for the mock.
- $options : array<string, mixed> = []
-
Additional options. See Client::addMockResponse()
mockClientPatch()
Add a mock response for a PATCH request.
public
mockClientPatch(string $url, Response $response[, array<string, mixed> $options = [] ]) : void
Parameters
- $url : string
-
The URL to mock
- $response : Response
-
The response for the mock.
- $options : array<string, mixed> = []
-
Additional options. See Client::addMockResponse()
mockClientPost()
Add a mock response for a POST request.
public
mockClientPost(string $url, Response $response[, array<string, mixed> $options = [] ]) : void
Parameters
- $url : string
-
The URL to mock
- $response : Response
-
The response for the mock.
- $options : array<string, mixed> = []
-
Additional options. See Client::addMockResponse()
mockClientPut()
Add a mock response for a PUT request.
public
mockClientPut(string $url, Response $response[, array<string, mixed> $options = [] ]) : void
Parameters
- $url : string
-
The URL to mock
- $response : Response
-
The response for the mock.
- $options : array<string, mixed> = []
-
Additional options. See Client::addMockResponse()
newClientResponse()
Create a new response.
public
newClientResponse([int $code = 200 ][, array<string|int, string> $headers = [] ][, string $body = '' ]) : Response
Parameters
- $code : int = 200
-
The response code to use. Defaults to 200
- $headers : array<string|int, string> = []
-
A list of headers for the response. Example
Content-Type: application/json
- $body : string = ''
-
The body for the response.