Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Property Summary
-
$_schema protected
Cake\Database\Schema\Table
The Cake\Database\Schema\Table for this fixture.
-
$connection public
string
Fixture Datasource
-
$created public
array
List of datasources where this fixture has been created
-
$fields public
array
Fields / Schema for the fixture.
-
$import public
array
Configuration for importing fixture schema
-
$records public
array
Fixture records to be inserted.
-
$table public
string
Full 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\Exception
on 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
void
Throws
Cake\Core\Exception\Exception
when 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
bool
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
bool
init() ¶ public
init(): void
Initialize the fixture.
Returns
void
Throws
Cake\ORM\Exception\MissingTableClassException
When 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
bool
schema() ¶ public
schema(Cake\Database\Schema\Table $schema = null): voidCake\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
voidCake\Database\Schema\Table
truncate() ¶ 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
bool
Property 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