W3cubDocs

/CakePHP 4.4

Trait HttpClientTrait

Define mock responses and have mocks automatically cleared.

Namespace: Cake\Http\TestSuite

Method Summary

Method Detail

cleanupMockResponses() public

cleanupMockResponses(): void

Resets mocked responses

Returns

void

mockClientDelete() public

mockClientDelete(string $url, Cake\Http\Client\Response $response, array<string, mixed> $options = []): void

Add a mock response for a DELETE request.

Parameters

string $url

The URL to mock

Cake\Http\Client\Response $response

The response for the mock.

array<string, mixed> $options optional

Additional options. See Client::addMockResponse()

Returns

void

mockClientGet() public

mockClientGet(string $url, Cake\Http\Client\Response $response, array<string, mixed> $options = []): void

Add a mock response for a GET request.

Parameters

string $url

The URL to mock

Cake\Http\Client\Response $response

The response for the mock.

array<string, mixed> $options optional

Additional options. See Client::addMockResponse()

Returns

void

mockClientPatch() public

mockClientPatch(string $url, Cake\Http\Client\Response $response, array<string, mixed> $options = []): void

Add a mock response for a PATCH request.

Parameters

string $url

The URL to mock

Cake\Http\Client\Response $response

The response for the mock.

array<string, mixed> $options optional

Additional options. See Client::addMockResponse()

Returns

void

mockClientPost() public

mockClientPost(string $url, Cake\Http\Client\Response $response, array<string, mixed> $options = []): void

Add a mock response for a POST request.

Parameters

string $url

The URL to mock

Cake\Http\Client\Response $response

The response for the mock.

array<string, mixed> $options optional

Additional options. See Client::addMockResponse()

Returns

void

mockClientPut() public

mockClientPut(string $url, Cake\Http\Client\Response $response, array<string, mixed> $options = []): void

Add a mock response for a PUT request.

Parameters

string $url

The URL to mock

Cake\Http\Client\Response $response

The response for the mock.

array<string, mixed> $options optional

Additional options. See Client::addMockResponse()

Returns

void

newClientResponse() public

newClientResponse(int $code = 200, array<string> $headers = [], string $body = ''): Cake\Http\Client\Response

Create a new response.

Parameters

int $code optional

The response code to use. Defaults to 200

array<string> $headers optional

A list of headers for the response. Example Content-Type: application/json

string $body optional

The body for the response.

Returns

Cake\Http\Client\Response

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/trait-Cake.Http.TestSuite.HttpClientTrait.html