Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Property Summary
-
$_constraints protected
array
Fixture constraints to be created.
-
$_schema protected
Cake\Database\Schema\TableSchema
The schema for this fixture.
-
$connection public
string
Fixture Datasource
-
$fields public
array
Fields / Schema for the fixture.
-
$import public
array|null
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.
-
_schemaFromReflection() protected
Build fixture schema directly from the datasource
-
_tableFromClass() protected
Returns the table name using the fixture class
-
connection() public
Get the connection name this fixture should be inserted into.
-
create() public
Create the fixture schema/mapping/definition
-
createConstraints() public
Build and execute SQL queries necessary to create the constraints for the fixture
-
drop() public
Run after all tests executed, should remove the table/collection from the connection.
-
dropConstraints() public
Build and execute SQL queries necessary to drop the constraints for the fixture
-
getTableSchema() public
Get and set the schema for this fixture.
-
init() public
Initialize the fixture.
-
insert() public
Run before each test is executed.
-
schema() public deprecated
Gets/Sets the TableSchema instance used by this fixture.
-
setTableSchema() public
Get and set the schema for this fixture.
-
sourceName() public
Get the table/collection name for this fixture.
-
truncate() public
Truncates the current fixture.
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.
_schemaFromReflection() ¶ protected
_schemaFromReflection(): void
Build fixture schema directly from the datasource
Returns
void
Throws
Cake\Core\Exception\Exception
when trying to reflect a table that does not exist
_tableFromClass() ¶ protected
_tableFromClass(): string
Returns the table name using the fixture class
Returns
string
connection() ¶ public
connection(): string
Get the connection name this fixture should be inserted into.
Returns
string
create() ¶ public
create(Cake\Datasource\ConnectionInterface $db): bool
Create the fixture schema/mapping/definition
Parameters
-
Cake\Datasource\ConnectionInterface
$db
Returns
bool
createConstraints() ¶ public
createConstraints(Cake\Datasource\ConnectionInterface $db): bool
Build and execute SQL queries necessary to create the constraints for the fixture
Parameters
-
Cake\Datasource\ConnectionInterface
$db
Returns
bool
drop() ¶ public
drop(Cake\Datasource\ConnectionInterface $db): bool
Run after all tests executed, should remove the table/collection from the connection.
Parameters
-
Cake\Datasource\ConnectionInterface
$db
Returns
bool
dropConstraints() ¶ public
dropConstraints(Cake\Datasource\ConnectionInterface $db): bool
Build and execute SQL queries necessary to drop the constraints for the fixture
Parameters
-
Cake\Datasource\ConnectionInterface
$db
Returns
bool
getTableSchema() ¶ public
getTableSchema(): Cake\Database\Schema\TableSchemaInterface|null
Get and set the schema for this fixture.
Returns
Cake\Database\Schema\TableSchemaInterface|null
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(Cake\Datasource\ConnectionInterface $db): Cake\Database\StatementInterface|bool
Run before each test is executed.
Should insert all the records into the test database.
Parameters
-
Cake\Datasource\ConnectionInterface
$db
Returns
Cake\Database\StatementInterface|bool
schema() ¶ public
schema(Cake\Database\Schema\TableSchema|null $schema = null): Cake\Database\Schema\TableSchema|null
Gets/Sets the TableSchema instance used by this fixture.
Parameters
-
Cake\Database\Schema\TableSchema|null
$schema optional The table to set.
Returns
Cake\Database\Schema\TableSchema|null
setTableSchema() ¶ public
setTableSchema(DatabaseTableSchemaInterface $schema): $this
Get and set the schema for this fixture.
Parameters
-
DatabaseTableSchemaInterface
$schema
Returns
$this
sourceName() ¶ public
sourceName(): string
Get the table/collection name for this fixture.
Returns
string
truncate() ¶ public
truncate(Cake\Datasource\ConnectionInterface $db): bool
Truncates the current fixture.
Parameters
-
Cake\Datasource\ConnectionInterface
$db
Returns
bool
Property Detail
$fields ¶ public
Fields / Schema for the fixture.
This array should be compatible with Cake\Database\Schema\Schema.
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 model
or table
key, to define
which table and which connection contain the schema to be
imported.
Type
array|null