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:
<?php
helper('test');
Available Functions¶
The following functions are available:
fake($model[, ?array $overrides = null[, $persist = true]])¶
-
Parameters
- $model
Model|object|stringInstance or name of the model to use with Fabricator - $overrides
array|nullOverriding data to pass toFabricator::setOverrides() - $persist
boolWhether to save the generated item to the database
- $model
-
Returns: A random fake item, saved to the database if
$persistis true -
Return type:
object|array
Uses CodeIgniter\Test\Fabricator to create a random item and optionally add it to the database.
Usage example:
<?php
use CodeIgniter\Test\CIUnitTestCase;
final class MyTestClass extends CIUnitTestCase
{
public function testUserAccess()
{
$user = fake('App\Models\UserModel');
$this->assertTrue($this->userHasAccess($user));
}
}