Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Property Summary
-
$_schema protected
Cake\Database\Schema\TableThe Cake\Database\Schema\Table for this fixture.
-
$connection public
stringFixture Datasource
-
$created public
arrayList of datasources where this fixture has been created
-
$fields public
arrayFields / Schema for the fixture.
-
$import public
arrayConfiguration for importing fixture schema
-
$records public
arrayFixture records to be inserted.
-
$table public
stringFull Table Name
Method Summary
-
__construct() public
Instantiate the fixture.
-
_getRecords() protected
Converts the internal records into data used to generate a query.
-
_schemaFromFields() protected
Build the fixtures table schema from the fields property.
-
_schemaFromImport() protected
Build fixture schema from a table in another datasource.
-
create() public
Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully.
-
drop() public
Run after all tests executed, should return SQL statement to drop table for this fixture.
-
init() public
Initialize the fixture.
-
insert() public
Run before each tests is executed, should return a set of SQL statements to insert records for the table of this fixture could be executed successfully.
-
schema() public
Get/Set the Cake\Database\Schema\Table instance used by this fixture.
-
truncate() public
Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after truncate.
Method Detail
__construct() ¶ public
__construct()
Instantiate the fixture.
Throws
Cake\Core\Exception\Exceptionon invalid datasource usage.
_getRecords() ¶ protected
_getRecords(): array
Converts the internal records into data used to generate a query.
Returns
array_schemaFromFields() ¶ protected
_schemaFromFields(): void
Build the fixtures table schema from the fields property.
Returns
void_schemaFromImport() ¶ protected
_schemaFromImport(): void
Build fixture schema from a table in another datasource.
Returns
voidThrows
Cake\Core\Exception\Exceptionwhen trying to import from an empty table.
create() ¶ public
create(Connection $db): bool
Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully.
Parameters
-
Connection$db An instance of the database object used to create the fixture table
Returns
boolTrue on success, false on failure
drop() ¶ public
drop(Connection $db): bool
Run after all tests executed, should return SQL statement to drop table for this fixture.
Parameters
-
Connection$db An instance of the database object used to create the fixture table
Returns
boolTrue on success, false on failure
init() ¶ public
init(): void
Initialize the fixture.
Returns
voidThrows
Cake\ORM\Exception\MissingTableClassExceptionWhen importing from a table that does not exist.
insert() ¶ public
insert(Connection $db): bool
Run before each tests is executed, should return a set of SQL statements to insert records for the table of this fixture could be executed successfully.
Parameters
-
Connection$db An instance of the database into which the records will be inserted
Returns
boolon success or if there are no records to insert, or false on failure
schema() ¶ public
schema(Cake\Database\Schema\Table $schema = null): void|Cake\Database\Schema\Table
Get/Set the Cake\Database\Schema\Table instance used by this fixture.
Parameters
-
Cake\Database\Schema\Table$schema optional The table to set.
Returns
void|Cake\Database\Schema\Tabletruncate() ¶ public
truncate(Connection $db): bool
Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after truncate.
Parameters
-
Connection$db A reference to a db instance
Returns
boolProperty Detail
$_schema ¶ protected
The Cake\Database\Schema\Table for this fixture.
Type
Cake\Database\Schema\Table$fields ¶ public
Fields / Schema for the fixture.
This array should be compatible with Cake\Database\Schema\Table.
The _constraints, _options and _indexes keys are reserved for defining
constraints, options and indexes respectively.
Type
array$import ¶ public
Configuration for importing fixture schema
Accepts a connection and table key, to define
which table and which connection contain the schema to be
imported.
Type
array