\CodeIgniter\TestFeatureTestCase

Class FeatureTestCase

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

Summary

Methods
Properties
Constants
loadDependencies()
tearDown()
seed()
dontSeeInDatabase()
seeInDatabase()
grabFromDatabase()
hasInDatabase()
seeNumRecords()
withSession()
skipEvents()
call()
get()
post()
put()
patch()
delete()
options()
No public properties found
No constants found
setUp()
withRoutes()
setupRequest()
populateGlobals()
$refresh
$seed
$basePath
$namespace
$DBGroup
$db
$migrations
$seeder
$insertCache
$routes
$session
$clean
N/A
No private methods found
No private properties found
N/A

Properties

$refresh

$refresh : boolean

Should the db be refreshed before each test?

Type

boolean

$seed

$seed : string

The name of the fixture used for all tests within this test case.

Type

string

$basePath

$basePath : string

The path to where we can find the seeds directory.

Allows overriding the default application directories.

Type

string

$namespace

$namespace : string

The namespace to help us find the migration classes.

Type

string

$DBGroup

$DBGroup : string

The name of the database group to connect to.

If not present, will use the defaultGroup.

Type

string

$migrations

$migrations : \CodeIgniter\Database\MigrationRunner|mixed

Migration Runner instance.

Type

\CodeIgniter\Database\MigrationRunner|mixed

$insertCache

$insertCache : array

Stores information needed to remove any rows inserted via $this->hasInDatabase();

Type

array

$session

$session : array

Values to be set in the SESSION global before running the test.

Type

array

$clean

$clean : boolean

Enabled auto clean op buffer after request call

Type

boolean

Methods

loadDependencies()

loadDependencies() 

Load any database test dependencies.

tearDown()

tearDown() 

Takes care of any required cleanup after the test, like removing any rows inserted via $this->hasInDatabase()

seed()

seed(string  $name) 

Seeds that database with a specific seeder.

Parameters

string $name

dontSeeInDatabase()

dontSeeInDatabase(string  $table, array  $where) : boolean

Asserts that records that match the conditions in $where do not exist in the database.

Parameters

string $table
array $where

Returns

boolean

seeInDatabase()

seeInDatabase(string  $table, array  $where) : boolean

Asserts that records that match the conditions in $where DO exist in the database.

Parameters

string $table
array $where

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean

grabFromDatabase()

grabFromDatabase(string  $table, string  $column, array  $where) : boolean

Fetches a single column from a database row with criteria matching $where.

Parameters

string $table
string $column
array $where

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean

hasInDatabase()

hasInDatabase(string  $table, array  $data) : boolean

Inserts a row into to the database. This row will be removed after the test has run.

Parameters

string $table
array $data

Returns

boolean

seeNumRecords()

seeNumRecords(integer  $expected, string  $table, array  $where) : boolean

Asserts that the number of rows in the database that match $where is equal to $expected.

Parameters

integer $expected
string $table
array $where

Throws

\CodeIgniter\Database\Exceptions\DatabaseException

Returns

boolean

withSession()

withSession(array  $values) : $this

Sets any values that should exist during this session.

Parameters

array $values

Returns

$this

skipEvents()

skipEvents() : $this

Don't run any events while running this test.

Returns

$this

call()

call(string  $method, string  $path, array|null  $params = null) : \CodeIgniter\Test\FeatureResponse

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

Parameters

string $method
string $path
array|null $params

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

\CodeIgniter\Test\FeatureResponse

get()

get(string  $path, array|null  $params = null) : \CodeIgniter\Test\FeatureResponse

Performs a GET request.

Parameters

string $path
array|null $params

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

\CodeIgniter\Test\FeatureResponse

post()

post(string  $path, array|null  $params = null) : \CodeIgniter\Test\FeatureResponse

Performs a POST request.

Parameters

string $path
array|null $params

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

\CodeIgniter\Test\FeatureResponse

put()

put(string  $path, array|null  $params = null) : \CodeIgniter\Test\FeatureResponse

Performs a PUT request

Parameters

string $path
array|null $params

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

\CodeIgniter\Test\FeatureResponse

patch()

patch(string  $path, array|null  $params = null) : \CodeIgniter\Test\FeatureResponse

Performss a PATCH request

Parameters

string $path
array|null $params

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

\CodeIgniter\Test\FeatureResponse

delete()

delete(string  $path, array|null  $params = null) : \CodeIgniter\Test\FeatureResponse

Performs a DELETE request.

Parameters

string $path
array|null $params

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

\CodeIgniter\Test\FeatureResponse

options()

options(string  $path, array|null  $params = null) : \CodeIgniter\Test\FeatureResponse

Performs an OPTIONS request.

Parameters

string $path
array|null $params

Throws

\CodeIgniter\Router\Exceptions\RedirectException
\Exception

Returns

\CodeIgniter\Test\FeatureResponse

setUp()

setUp() 

Ensures that the database is cleaned up to a known state before each test runs.

Throws

\CodeIgniter\Exceptions\ConfigException

withRoutes()

withRoutes(array  $routes = null) : $this

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

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

Parameters

array $routes

Returns

$this

setupRequest()

setupRequest(string  $method, string|null  $path = null, array|null  $params = null) : \CodeIgniter\HTTP\IncomingRequest

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

Parameters

string $method
string|null $path
array|null $params

Returns

\CodeIgniter\HTTP\IncomingRequest

populateGlobals()

populateGlobals(string  $method, \CodeIgniter\HTTP\Request  $request, array|null  $params = null) : \CodeIgniter\HTTP\Request

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

Always populate the GET vars based on the URI.

Parameters

string $method
\CodeIgniter\HTTP\Request $request
array|null $params

Throws

\ReflectionException

Returns

\CodeIgniter\HTTP\Request