Documentation

FeatureTestTrait

Trait FeatureTestTrait

Provides additional utilities for doing full HTTP testing against your application in trait format.

Table of Contents

call()  : TestResponse
Calls a single URI, executes it, and returns a TestResponse instance that can be used to run many assertions against.
delete()  : TestResponse
Performs a DELETE request.
get()  : TestResponse
Performs a GET request.
options()  : TestResponse
Performs an OPTIONS request.
patch()  : TestResponse
Performss a PATCH request
post()  : TestResponse
Performs a POST request.
put()  : TestResponse
Performs a PUT request
skipEvents()  : $this
Don't run any events while running this test.
withBody()  : $this
Set the raw body for the request
withBodyFormat()  : $this
Set the format the request's body should have.
withHeaders()  : $this
Set request's headers
withSession()  : $this
Sets any values that should exist during this session.
populateGlobals()  : Request
Populates the data of our Request with "global" data relevant to the request, like $_POST data.
setRequestBody()  : Request
Set the request's body formatted according to the value in $this->bodyFormat.
setupHeaders()  : IncomingRequest
Setup the custom request's headers
setupRequest()  : IncomingRequest
Setup a Request object to use so that CodeIgniter won't try to auto-populate some of the items.
withRoutes()  : $this
Sets a RouteCollection that will override the application's route collection.

Methods

call()

Calls a single URI, executes it, and returns a TestResponse instance that can be used to run many assertions against.

public call(string $method, string $path[, array<string|int, mixed>|null $params = null ]) : TestResponse
Parameters
$method : string
$path : string
$params : array<string|int, mixed>|null = null
Tags
throws
RedirectException
throws
Exception
Return values
TestResponse

delete()

Performs a DELETE request.

public delete(string $path[, array<string|int, mixed>|null $params = null ]) : TestResponse
Parameters
$path : string
$params : array<string|int, mixed>|null = null
Tags
throws
RedirectException
throws
Exception
Return values
TestResponse

options()

Performs an OPTIONS request.

public options(string $path[, array<string|int, mixed>|null $params = null ]) : TestResponse
Parameters
$path : string
$params : array<string|int, mixed>|null = null
Tags
throws
RedirectException
throws
Exception
Return values
TestResponse

patch()

Performss a PATCH request

public patch(string $path[, array<string|int, mixed>|null $params = null ]) : TestResponse
Parameters
$path : string
$params : array<string|int, mixed>|null = null
Tags
throws
RedirectException
throws
Exception
Return values
TestResponse

skipEvents()

Don't run any events while running this test.

public skipEvents() : $this
Return values
$this

withBody()

Set the raw body for the request

public withBody(mixed $body) : $this
Parameters
$body : mixed
Return values
$this

withBodyFormat()

Set the format the request's body should have.

public withBodyFormat(string $format) : $this
Parameters
$format : string

The desired format. Currently supported formats: xml, json

Return values
$this

withHeaders()

Set request's headers

public withHeaders([array<string|int, mixed> $headers = [] ]) : $this

Example of use withHeaders([ 'Authorization' => 'Token' ])

Parameters
$headers : array<string|int, mixed> = []

Array of headers

Return values
$this

withSession()

Sets any values that should exist during this session.

public withSession([array<string|int, mixed>|null $values = null ]) : $this
Parameters
$values : array<string|int, mixed>|null = null

Array of values, or null to use the current $_SESSION

Return values
$this

populateGlobals()

Populates the data of our Request with "global" data relevant to the request, like $_POST data.

protected populateGlobals(string $method, Request $request[, array<string|int, mixed>|null $params = null ]) : Request

Always populate the GET vars based on the URI.

Parameters
$method : string
$request : Request
$params : array<string|int, mixed>|null = null
Tags
throws
ReflectionException
Return values
Request

setRequestBody()

Set the request's body formatted according to the value in $this->bodyFormat.

protected setRequestBody(Request $request[, null|array<string|int, mixed> $params = null ]) : Request

This allows the body to be formatted in a way that the controller is going to expect as in the case of testing a JSON or XML API.

Parameters
$request : Request
$params : null|array<string|int, mixed> = null

The parameters to be formatted and put in the body. If this is empty, it will get the what has been loaded into the request global of the request class.

Return values
Request

setupRequest()

Setup a Request object to use so that CodeIgniter won't try to auto-populate some of the items.

protected setupRequest(string $method[, string|null $path = null ]) : IncomingRequest
Parameters
$method : string
$path : string|null = null
Return values
IncomingRequest

withRoutes()

Sets a RouteCollection that will override the application's route collection.

protected withRoutes([array<string|int, mixed> $routes = null ]) : $this

Example routes: [ ['get', 'home', 'Home::index'] ]

Parameters
$routes : array<string|int, mixed> = null
Return values
$this

Search results