CodeIgniter v4.5 API

FeatureTestTrait

Trait FeatureTestTrait

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

Table of Contents

Methods

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

HTTP verb

$path : string
$params : array<string|int, mixed>|null = null
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

get()

Performs a GET request.

public get(string $path[, array<string|int, mixed>|null $params = null ]) : TestResponse
Parameters
$path : string

URI path relative to baseURL. May include query.

$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

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(string $body) : $this
Parameters
$body : string
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 $name, Request $request[, array<string|int, mixed>|null $params = null ]) : Request

Always populate the GET vars based on the URI.

Parameters
$name : string

Superglobal name (lowercase)

$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[, array<string|int, mixed>|null $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 : array<string|int, mixed>|null = null

The parameters to be formatted and put in the body.

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

HTTP verb

$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>|null $routes = null ]) : $this

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

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

Array to set routes

Return values
$this

        
On this page

Search results