CIUnitTestCase
extends TestCase
in package
uses
ReflectionHelper
Framework test case for PHPUnit.
Table of Contents
Properties
- $app : CodeIgniter
- $basePath : string
- The path to the seeds directory.
- $bodyFormat : string
- Allows for formatting the request body to what the controller is going to expect
- $clean : bool
- Enabled auto clean op buffer after request call
- $db : BaseConnection
- Our database connection.
- $DBGroup : non-empty-string
- The name of the database group to connect to.
- $headers : array<string|int, mixed>
- Custom request's headers
- $insertCache : array<string|int, mixed>
- Stores information needed to remove any rows inserted via $this->hasInDatabase();
- $migrate : bool
- Should run db migration?
- $migrateOnce : bool
- Should run db migration only once?
- $migrations : MigrationRunner|null
- Migration Runner instance.
- $namespace : array<string|int, mixed>|string|null
- The namespace(s) to help us find the migration classes.
- $refresh : bool
- Should the db be refreshed before test?
- $requestBody : mixed
- Allows for directly setting the body to what it needs to be.
- $routes : RouteCollection|null
- If present, will override application routes when using call().
- $seed : Seeder>|array<int, Seeder>>
- The seed file(s) used for all tests within this test case.
- $seeder : Seeder
- Seeder instance
- $seedOnce : bool
- Should run seeding only once?
- $session : array<string|int, mixed>
- Values to be set in the SESSION global before running the test.
- $setUpMethods : array<int, string>
- Methods to run during setUp.
- $tearDownMethods : array<int, string>
- Methods to run during tearDown.
- $traits : array<string|int, mixed>|null
- Store of identified traits.
Methods
- assertCloseEnough() : mixed
- Custom function to test that two values are "close enough".
- assertCloseEnoughString() : bool|void
- Custom function to test that two values are "close enough".
- assertEventTriggered() : bool
- Hooks into CodeIgniter's Events system to check if a specific event was triggered or not.
- assertHeaderEmitted() : void
- Hooks into xdebug's headers capture, looking for presence of a specific header emitted.
- assertHeaderNotEmitted() : void
- Hooks into xdebug's headers capture, looking for absence of a specific header emitted.
- assertLogContains() : void
- Asserts that there is a log record that contains `$logMessage` in the message.
- assertLogged() : bool
- Custom function to hook into CodeIgniter's Logging mechanism to check if certain messages were logged during code execution.
- getPrivateMethodInvoker() : Closure
- Find a private method invoker.
- getPrivateProperty() : mixed
- Retrieve a private property.
- setPrivateProperty() : void
- Set a private property.
- setUpBeforeClass() : void
- Load the helpers.
- createApplication() : CodeIgniter
- Loads up an instance of CodeIgniter and gets the environment setup.
- getHeaderEmitted() : string|null
- Return first matching emitted header.
- mockCache() : mixed
- Injects the mock Cache driver to prevent filesystem collisions
- mockEmail() : mixed
- Injects the mock email driver so no emails really send
- mockSession() : mixed
- Injects the mock session driver into Services
- resetFactories() : mixed
- Resets shared instanced for all Factories components
- resetServices() : mixed
- Resets shared instanced for all Services
- setUp() : void
- tearDown() : void
- callTraitMethods() : void
- Checks for traits with corresponding methods for setUp or tearDown.
- getAccessibleRefProperty() : ReflectionProperty
- Find an accessible property.
Properties
$app
protected
CodeIgniter
$app
$basePath
The path to the seeds directory.
protected
string
$basePath
= SUPPORTPATH . 'Database'
Allows overriding the default application directories.
$bodyFormat
Allows for formatting the request body to what the controller is going to expect
protected
string
$bodyFormat
= ''
$clean
Enabled auto clean op buffer after request call
protected
bool
$clean
= true
$db
Our database connection.
protected
BaseConnection
$db
$DBGroup
The name of the database group to connect to.
protected
non-empty-string
$DBGroup
= 'tests'
If not present, will use the defaultGroup.
$headers
Custom request's headers
protected
array<string|int, mixed>
$headers
= []
$insertCache
Stores information needed to remove any rows inserted via $this->hasInDatabase();
protected
array<string|int, mixed>
$insertCache
= []
$migrate
Should run db migration?
protected
bool
$migrate
= true
$migrateOnce
Should run db migration only once?
protected
bool
$migrateOnce
= false
$migrations
Migration Runner instance.
protected
MigrationRunner|null
$migrations
$namespace
The namespace(s) to help us find the migration classes.
protected
array<string|int, mixed>|string|null
$namespace
= 'Tests\Support'
null
is equivalent to running spark migrate --all
.
Note that running "all" runs migrations in date order,
but specifying namespaces runs them in namespace order (then date)
$refresh
Should the db be refreshed before test?
protected
bool
$refresh
= true
$requestBody
Allows for directly setting the body to what it needs to be.
protected
mixed
$requestBody
= ''
$routes
If present, will override application routes when using call().
protected
RouteCollection|null
$routes
$seed
The seed file(s) used for all tests within this test case.
protected
Seeder>|array<int, Seeder>>
$seed
= ''
Should be fully-namespaced or relative to $basePath
$seeder
Seeder instance
protected
Seeder
$seeder
$seedOnce
Should run seeding only once?
protected
bool
$seedOnce
= false
$session
Values to be set in the SESSION global before running the test.
protected
array<string|int, mixed>
$session
= []
$setUpMethods
Methods to run during setUp.
protected
array<int, string>
$setUpMethods
= ['resetFactories', 'mockCache', 'mockEmail', 'mockSession']
WARNING: Do not override unless you know exactly what you are doing. This property may be deprecated in the future.
array of methods
$tearDownMethods
Methods to run during tearDown.
protected
array<int, string>
$tearDownMethods
= []
WARNING: This property may be deprecated in the future.
array of methods
$traits
Store of identified traits.
private
array<string|int, mixed>|null
$traits
= null
Methods
assertCloseEnough()
Custom function to test that two values are "close enough".
public
assertCloseEnough(int $expected, float|int $actual[, string $message = '' ][, int $tolerance = 1 ]) : mixed
This is intended for extended execution time testing, where the result is close but not exactly equal to the expected time, for reasons beyond our control.
Parameters
- $expected : int
- $actual : float|int
- $message : string = ''
- $tolerance : int = 1
Tags
assertCloseEnoughString()
Custom function to test that two values are "close enough".
public
assertCloseEnoughString(mixed $expected, mixed $actual[, string $message = '' ][, int $tolerance = 1 ]) : bool|void
This is intended for extended execution time testing, where the result is close but not exactly equal to the expected time, for reasons beyond our control.
Parameters
- $expected : mixed
- $actual : mixed
- $message : string = ''
- $tolerance : int = 1
Tags
Return values
bool|voidassertEventTriggered()
Hooks into CodeIgniter's Events system to check if a specific event was triggered or not.
public
assertEventTriggered(string $eventName) : bool
Parameters
- $eventName : string
Tags
Return values
boolassertHeaderEmitted()
Hooks into xdebug's headers capture, looking for presence of a specific header emitted.
public
assertHeaderEmitted(string $header[, bool $ignoreCase = false ]) : void
Parameters
- $header : string
-
The leading portion of the header we are looking for
- $ignoreCase : bool = false
assertHeaderNotEmitted()
Hooks into xdebug's headers capture, looking for absence of a specific header emitted.
public
assertHeaderNotEmitted(string $header[, bool $ignoreCase = false ]) : void
Parameters
- $header : string
-
The leading portion of the header we don't want to find
- $ignoreCase : bool = false
assertLogContains()
Asserts that there is a log record that contains `$logMessage` in the message.
public
assertLogContains(string $level, string $logMessage[, string $message = '' ]) : void
Parameters
- $level : string
- $logMessage : string
- $message : string = ''
assertLogged()
Custom function to hook into CodeIgniter's Logging mechanism to check if certain messages were logged during code execution.
public
assertLogged(string $level[, string|null $expectedMessage = null ]) : bool
Parameters
- $level : string
- $expectedMessage : string|null = null
Return values
boolgetPrivateMethodInvoker()
Find a private method invoker.
public
static getPrivateMethodInvoker(object|string $obj, string $method) : Closure
Parameters
- $obj : object|string
-
object or class name
- $method : string
-
method name
Tags
Return values
ClosuregetPrivateProperty()
Retrieve a private property.
public
static getPrivateProperty(object|string $obj, string $property) : mixed
Parameters
- $obj : object|string
-
object or class name
- $property : string
-
property name
Tags
setPrivateProperty()
Set a private property.
public
static setPrivateProperty(object|string $obj, string $property, mixed $value) : void
Parameters
- $obj : object|string
-
object or class name
- $property : string
-
property name
- $value : mixed
-
value
Tags
setUpBeforeClass()
Load the helpers.
public
static setUpBeforeClass() : void
createApplication()
Loads up an instance of CodeIgniter and gets the environment setup.
protected
createApplication() : CodeIgniter
Return values
CodeIgnitergetHeaderEmitted()
Return first matching emitted header.
protected
getHeaderEmitted(string $header[, bool $ignoreCase = false ][, string $method = __METHOD__ ]) : string|null
Parameters
- $header : string
- $ignoreCase : bool = false
- $method : string = __METHOD__
Return values
string|nullmockCache()
Injects the mock Cache driver to prevent filesystem collisions
protected
mockCache() : mixed
mockEmail()
Injects the mock email driver so no emails really send
protected
mockEmail() : mixed
mockSession()
Injects the mock session driver into Services
protected
mockSession() : mixed
resetFactories()
Resets shared instanced for all Factories components
protected
resetFactories() : mixed
resetServices()
Resets shared instanced for all Services
protected
resetServices([bool $initAutoloader = true ]) : mixed
Parameters
- $initAutoloader : bool = true
setUp()
protected
setUp() : void
tearDown()
protected
tearDown() : void
callTraitMethods()
Checks for traits with corresponding methods for setUp or tearDown.
private
callTraitMethods(string $stage) : void
Parameters
- $stage : string
-
'setUp' or 'tearDown'
getAccessibleRefProperty()
Find an accessible property.
private
static getAccessibleRefProperty(object|string $obj, string $property) : ReflectionProperty
Parameters
- $obj : object|string
- $property : string