Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Properties summary
- $_constraints protected
arrayFixture constraints to be created.
- $_schema protected
\Cake\Database\Schema\TableSchemaInterface&\Cake\Database\Schema\SqlGeneratorInterfaceThe schema for this fixture.
- $_tableLocator protected
\Cake\ORM\Locator\LocatorInterface|nullTable locator instance
- $connection public
stringFixture Datasource
- $fields public
arrayFields / Schema for the fixture.
- $import public
array|nullConfiguration for importing fixture schema
- $records public
arrayFixture records to be inserted.
- $table public
stringFull Table Name
Method Summary
- createConstraints() public
Build and execute SQL queries necessary to create the constraints for the fixture
- dropConstraints() public
Build and execute SQL queries necessary to drop the constraints for the fixture
Method Detail
__construct() public
__construct()
Instantiate the fixture.
Throws
Cake\Core\Exception\Exceptionon invalid datasource usage.
_getRecords() protected
_getRecords()
Converts the internal records into data used to generate a query.
Returns
array_schemaFromFields() protected
_schemaFromFields()
Build the fixtures table schema from the fields property.
_schemaFromImport() protected
_schemaFromImport()
Build fixture schema from a table in another datasource.
Throws
Cake\Core\Exception\Exceptionwhen trying to import from an empty table.
_schemaFromReflection() protected
_schemaFromReflection()
Build fixture schema directly from the datasource
Throws
Cake\Core\Exception\Exceptionwhen trying to reflect a table that does not exist
_tableFromClass() protected
_tableFromClass()
Returns the table name using the fixture class
Returns
stringconnection() public
connection()
Get the connection name this fixture should be inserted into.
Returns
stringcreate() public
create(\Cake\Datasource\ConnectionInterface $db)
Create the fixture schema/mapping/definition
Parameters
-
\Cake\Datasource\ConnectionInterface$db An instance of the connection the fixture should be created on.
Returns
boolTrue on success, false on failure.
createConstraints() public
createConstraints(\Cake\Datasource\ConnectionInterface $db)
Build and execute SQL queries necessary to create the constraints for the fixture
Parameters
-
\Cake\Datasource\ConnectionInterface$db An instance of the database into which the constraints will be created.
Returns
boolon success or if there are no constraints to create, or false on failure
drop() public
drop(\Cake\Datasource\ConnectionInterface $db)
Run after all tests executed, should remove the table/collection from the connection.
Parameters
-
\Cake\Datasource\ConnectionInterface$db An instance of the connection the fixture should be removed from.
Returns
boolTrue on success, false on failure.
dropConstraints() public
dropConstraints(\Cake\Datasource\ConnectionInterface $db)
Build and execute SQL queries necessary to drop the constraints for the fixture
Parameters
-
\Cake\Datasource\ConnectionInterface$db An instance of the database into which the constraints will be dropped.
Returns
boolon success or if there are no constraints to drop, or false on failure
getTableLocator() public
getTableLocator()
Gets the table locator.
Returns
\Cake\ORM\Locator\LocatorInterfacegetTableSchema() public
getTableSchema()
Get and set the schema for this fixture.
Returns
\Cake\Database\Schema\TableSchemaInterface&\Cake\Database\Schema\SqlGeneratorInterfaceinit() public
init()
Initialize the fixture.
Throws
Cake\ORM\Exception\MissingTableClassExceptionWhen importing from a table that does not exist.
insert() public
insert(\Cake\Datasource\ConnectionInterface $db)
Run before each test is executed.
Should insert all the records into the test database.
Parameters
-
\Cake\Datasource\ConnectionInterface$db An instance of the connection into which the records will be inserted.
Returns
\Cake\Database\StatementInterface|boolon success or if there are no records to insert, or false on failure.
setTableLocator() public
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator)
Sets the table locator.
Parameters
-
\Cake\ORM\Locator\LocatorInterface$tableLocator LocatorInterface instance.
Returns
$thissetTableSchema() public
setTableSchema(mixed $schema)
Get and set the schema for this fixture.
Parameters
-
\Cake\Database\Schema\TableSchemaInterface&\Cake\Database\Schema\SqlGeneratorInterface$schema The table to set.
Returns
$thissourceName() public
sourceName()
Get the table/collection name for this fixture.
Returns
stringtruncate() public
truncate(\Cake\Datasource\ConnectionInterface $db)
Truncates the current fixture.
Parameters
-
\Cake\Datasource\ConnectionInterface$db A reference to a db instance
Returns
boolProperty Detail
$_constraints protected
Fixture constraints to be created.
Type
array$_schema protected
The schema for this fixture.
Type
\Cake\Database\Schema\TableSchemaInterface&\Cake\Database\Schema\SqlGeneratorInterface$_tableLocator protected
Table locator instance
Type
\Cake\ORM\Locator\LocatorInterface|null$connection public
Fixture Datasource
Type
string$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$records public
Fixture records to be inserted.
Type
array$table public
Full Table Name
Type
string
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.0/class-Cake.TestSuite.Fixture.TestFixture.html