Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Properties summary
- $_constraints protected
array
Fixture constraints to be created.
- $_schema protected
\Cake\Database\Schema\TableSchemaInterface&\Cake\Database\Schema\SqlGeneratorInterface
The schema for this fixture.
- $_tableLocator protected
\Cake\ORM\Locator\LocatorInterface|null
Table locator instance
- $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
- 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\Exception
on 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\Exception
when trying to import from an empty table.
_schemaFromReflection() protected
_schemaFromReflection()
Build fixture schema directly from the datasource
Throws
Cake\Core\Exception\Exception
when trying to reflect a table that does not exist
_tableFromClass() protected
_tableFromClass()
Returns the table name using the fixture class
Returns
string
connection() public
connection()
Get the connection name this fixture should be inserted into.
Returns
string
create() 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
bool
True 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
bool
on 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
bool
True 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
bool
on success or if there are no constraints to drop, or false on failure
getTableLocator() public
getTableLocator()
Gets the table locator.
Returns
\Cake\ORM\Locator\LocatorInterface
getTableSchema() public
getTableSchema()
Get and set the schema for this fixture.
Returns
\Cake\Database\Schema\TableSchemaInterface&\Cake\Database\Schema\SqlGeneratorInterface
init() public
init()
Initialize the fixture.
Throws
Cake\ORM\Exception\MissingTableClassException
When 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|bool
on 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
$this
setTableSchema() 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
$this
sourceName() public
sourceName()
Get the table/collection name for this fixture.
Returns
string
truncate() public
truncate(\Cake\Datasource\ConnectionInterface $db)
Truncates the current fixture.
Parameters
-
\Cake\Datasource\ConnectionInterface
$db A reference to a db instance
Returns
bool
Property 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