Documentation

GuzzleTestTrait

Class GuzzleTestTrait

This trait defines a number of helper functions for testing Guzzle-based logic, such as a payment-processing gateway.

Use this in a headless test for which you need to mock outbound HTTP requests from Civi. Alternatively, to write an E2E test with inbound HTTP requests to Civi, see HttpTestTrait.

Table of Contents

Properties

$baseUri  : string
The url to mock-interact with.
$container  : array<string|int, mixed>
Array containing guzzle history of requests and responses.
$guzzleClient  : Client
$mockHandler  : MockHandler
Mockhandler to simulate guzzle requests.

Methods

getBaseUri()  : mixed
getContainer()  : array<string|int, mixed>
getGuzzleClient()  : Client
getMockHandler()  : MockHandler
setBaseUri()  : mixed
setContainer()  : mixed
setGuzzleClient()  : mixed
setMockHandler()  : mixed
createMockHandler()  : mixed
createMockHandlerForFiles()  : mixed
getRequestBodies()  : array<string|int, mixed>
Get the bodies of the requests sent via Guzzle.
getRequestHeaders()  : array<string|int, mixed>
Get the bodies of the requests sent via Guzzle.
getRequestUrls()  : array<string|int, mixed>
Get the bodies of the requests sent via Guzzle.
getResponseBodies()  : array<string|int, mixed>
Get the bodies of the responses returned via Guzzle.
setUpClientWithHistoryContainer()  : mixed
Set up a guzzle client with a history container.

Properties

$container

Array containing guzzle history of requests and responses.

protected array<string|int, mixed> $container

$mockHandler

Mockhandler to simulate guzzle requests.

protected MockHandler $mockHandler

Methods

getContainer()

public getContainer() : array<string|int, mixed>
Return values
array<string|int, mixed>

getGuzzleClient()

public getGuzzleClient() : Client
Return values
Client

getMockHandler()

public getMockHandler() : MockHandler
Return values
MockHandler

setBaseUri()

public setBaseUri(mixed $baseUri) : mixed
Parameters
$baseUri : mixed

setContainer()

public setContainer(array<string|int, mixed> $container) : mixed
Parameters
$container : array<string|int, mixed>

setGuzzleClient()

public setGuzzleClient(Client $guzzleClient) : mixed
Parameters
$guzzleClient : Client

setMockHandler()

public setMockHandler(MockHandler $mockHandler) : mixed
Parameters
$mockHandler : MockHandler

createMockHandler()

protected createMockHandler(mixed $responses) : mixed
Parameters
$responses : mixed

createMockHandlerForFiles()

protected createMockHandlerForFiles(mixed $files) : mixed
Parameters
$files : mixed

getRequestBodies()

Get the bodies of the requests sent via Guzzle.

protected getRequestBodies() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRequestHeaders()

Get the bodies of the requests sent via Guzzle.

protected getRequestHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRequestUrls()

Get the bodies of the requests sent via Guzzle.

protected getRequestUrls() : array<string|int, mixed>
Return values
array<string|int, mixed>

getResponseBodies()

Get the bodies of the responses returned via Guzzle.

protected getResponseBodies() : array<string|int, mixed>
Return values
array<string|int, mixed>

setUpClientWithHistoryContainer()

Set up a guzzle client with a history container.

protected setUpClientWithHistoryContainer() : mixed

After you have run the requests you can inspect $this->container for the outgoing requests and incoming responses.

If $this->mock is defined then no outgoing http calls will be made and the responses configured on the handler will be returned instead of replies from a remote provider.


        
On this page

Search results