Test Helper

The Test Helper file contains functions that assist in testing your project.

Loading this Helper

This helper is loaded using the following code:

helper('test');

Available Functions

The following functions are available:

fake($model, array $overrides = null)
Parameters:
  • $model (Model|object|string) – Instance or name of the model to use with Fabricator
  • $overrides (array|null) – Overriding data to pass to Fabricator::setOverrides()
Returns:

A random fake item created and added to the database by Fabricator

Return type:

object|array

Uses CodeIgniter\Test\Fabricator to create a random item and add it to the database.

Usage example:

public function testUserAccess()
{
    $user = fake('App\Models\UserModel');

    $this->assertTrue($this->userHasAccess($user));
}