Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
- Cake\TestSuite\Fixture\TestFixture implements Cake\Datasource\FixtureInterface, Cake\Datasource\TableSchemaInterface, Cake\Database\Schema\TableSchemaAwareInterface uses Cake\ORM\Locator\LocatorAwareTrait
Properties summary
-
$_constraints
protectedarray
Fixture constraints to be created. -
$_schema
protectedThe schema for this fixture. -
$connection
publicstring
Fixture Datasource -
$fields
publicarray
Fields / Schema for the fixture. -
$import
publicarray|null
Configuration for importing fixture schema -
$records
publicarray
Fixture records to be inserted. -
$table
publicstring
Full Table Name
Inherited Properties
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
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
_getRecords() protected ¶
_getRecords( )
Converts the internal records into data used to generate a query.
Returns
_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
_schemaFromReflection() protected ¶
_schemaFromReflection( )
Build fixture schema directly from the datasource
Throws
_tableFromClass() protected ¶
_tableFromClass( )
Returns the table name using the fixture class
Returns
connection() public ¶
connection( )
Get the connection name this fixture should be inserted into.
Returns
Implementation of
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
True on success, false on failure.
Implementation of
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
on success or if there are no constraints to create, or false on failure
Implementation of
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
True on success, false on failure.
Implementation of
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
on success or if there are no constraints to drop, or false on failure
Implementation of
getTableSchema() public ¶
getTableSchema( )
Get and set the schema for this fixture.
Returns
Implementation of
insert() public ¶
insert( Cake\Datasource\ConnectionInterface
$db )
Run before each test is executed.
Parameters
-
Cake\Datasource\ConnectionInterface
$db - An instance of the connection into which the records will be inserted.
Returns
Cake\Database\StatementInterface
|booleanon success or if there are no records to insert, or false on failure.
Implementation of
schema() public ¶
schema( Cake\Database\Schema\TableSchema
$schema null )
Gets/Sets the TableSchema instance used by this fixture.
Deprecated
Parameters
-
Cake\Database\Schema\TableSchema
$schema optional null - The table to set.
Returns
Implementation of
setTableSchema() public ¶
setTableSchema( Cake\Database\Schema\TableSchemaInterface
$schema )
Get and set the schema for this fixture.
Parameters
-
Cake\Database\Schema\TableSchemaInterface
$schema - The table to set.
Returns
$this
Implementation of
sourceName() public ¶
sourceName( )
Get the table/collection name for this fixture.
Returns
Implementation of
truncate() public ¶
truncate( Cake\Datasource\ConnectionInterface
$db )
Truncates the current fixture.
Parameters
-
Cake\Datasource\ConnectionInterface
$db - A reference to a db instance
Returns
Implementation of
Methods used from Cake\ORM\Locator\LocatorAwareTrait
setTableLocator() public ¶
setTableLocator( Cake\ORM\Locator\LocatorInterface
$tableLocator )
Sets the table locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator - LocatorInterface instance.
Returns
$this
tableLocator() public ¶
tableLocator( Cake\ORM\Locator\LocatorInterface
$tableLocator null )
Sets the table locator. If no parameters are passed, it will return the currently used locator.
Deprecated
Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator optional null - LocatorInterface instance.
Returns
Magic methods inherited from Cake\Datasource\TableSchemaInterface
getTableSchema()
|
Properties detail
$fields ¶
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.
[]