ApiTest

PageTester extends APITester
in package

Page Tester class.

Contains all the automated API tests.

Table of Contents

Properties

$client  : Client
Guzzle client object.
$cookieJar  : CookieJar
Cookie jar object.
$history  : array<int, array<string, mixed>>
The history container.
$response  : ResponseInterface
The complete response object.

Methods

__construct()  : mixed
Constructor method.
apiEndPointTest()  : string
Api end point test method.
checkBody()  : string
Check body method.
checkStatus()  : int
Check status method.
testApiEndPoint()  : string
Test API end point method.
testPage()  : string
Test API end point method.
webPageTest()  : string
Test web page method.

Properties

$client

Guzzle client object.

public Client $client

$cookieJar

Cookie jar object.

public CookieJar $cookieJar

$history

The history container.

public array<int, array<string, mixed>> $history = []

$response

The complete response object.

public ResponseInterface $response

Methods

__construct()

Constructor method.

public __construct(string $host[, string $requestContentType = 'application/json' ][, string $responseContentType = 'application/json' ]) : mixed
Parameters
$host : string

The host for the tests.

$requestContentType : string = 'application/json'

The request data type.

$responseContentType : string = 'application/json'

The response data type.

apiEndPointTest()

Api end point test method.

public apiEndPointTest(string $method, string $endPoint[, null|string|array<string|int, mixed> $data = null ][, TestOptions $testOptions = new TestOptions() ]) : string
Parameters
$method : string

The HTTP method to use.

$endPoint : string

The API end point.

$data : null|string|array<string|int, mixed> = null

The JSON or form data to process. Can be null, string, or various array structures.

$testOptions : TestOptions = new TestOptions()

The options object. Contains various options.

Tags
throws
RequestException

If the request fails without a response.

Exception

If request processing fails.

Return values
string

checkBody()

Check body method.

public static checkBody(ResponseInterface $response[, bool $expectedJson = true ][, bool $errorExpected = false ][, bool $contentRequired = true ][, bool $tryBasicAsserts = true ]) : string
Parameters
$response : ResponseInterface

The PSR7 response object.

$expectedJson : bool = true

Indicates whether the body is expected to be json or not.

$errorExpected : bool = false

Indicates whether an error field is expected in the response or not.

$contentRequired : bool = true

Indicates whether content is required in the response body.

$tryBasicAsserts : bool = true

Indicates whether to try running basic asserts or not.

Return values
string

checkStatus()

Check status method.

public static checkStatus(ResponseInterface $response[, bool $errorExpected = false ][, bool $tryBasicAsserts = true ]) : int
Parameters
$response : ResponseInterface

The PSR7 response object.

$errorExpected : bool = false

Indicates whether an error is expected or not.

$tryBasicAsserts : bool = true

Indicates whether to try running basic asserts or not.

Return values
int

testApiEndPoint()

Test API end point method.

public testApiEndPoint(string $method, string $endPoint, null|string|array<string|int, mixed> $data[, bool|string $dataType = false ][, bool $isError = false ][, bool $errorRequired = false ][, bool $contentRequired = true ]) : string

since v1.6.32, use apiEndPointTest() instead.

Parameters
$method : string

The HTTP method to use.

$endPoint : string

The API end point.

$data : null|string|array<string|int, mixed>

The JSON data to process.

$dataType : bool|string = false

The data type. True, if it is multipart form data. Implying some of the data may be binary. If it is a string, the string indicates the type of data ('body', 'json', 'form_params').

$isError : bool = false

Indicates whether an error is expected or not.

$errorRequired : bool = false

Indicates whether an error field is expected in the response or not.

$contentRequired : bool = true

Indicates whether content is required in the response body.

Return values
string

testPage()

Test API end point method.

public testPage(string $method, string $endPoint, null|string|array<string|int, mixed> $data[, bool $multiPartData = false ][, bool $isError = false ]) : string

since v1.6.32, use webPageTest() instead.

Parameters
$method : string

The HTTP method to use.

$endPoint : string

The API end point.

$data : null|string|array<string|int, mixed>

The JSON or form data to process. Can be null, string, or various array structures.

$multiPartData : bool = false

Data is multipart form data. Implying some of the data may be binary.

$isError : bool = false

Indicates whether an error is expected or not.

Return values
string

webPageTest()

Test web page method.

public webPageTest(string $method, string $endPoint[, null|string|array<string|int, mixed> $data = null ][, TestOptions $testOptions = new TestOptions() ]) : string
Parameters
$method : string

The HTTP method to use.

$endPoint : string

The API end point.

$data : null|string|array<string|int, mixed> = null

The JSON or form data to process. Can be null, string, or various array structures.

$testOptions : TestOptions = new TestOptions()

The options object. Contains various options.

Tags
throws
Exception

If an unexpected exception occurs during the request.

Return values
string
On this page

Search results