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
Properties summary
-  $_constraintsprotectedFixture constraints to be created.array
-  The schema for this fixture.$_schemaprotected
-  $connectionpublicFixture Datasourcestring
-  $fieldspublicFields / Schema for the fixture.array
-  $importpublicConfiguration for importing fixture schemaarray|null
-  $recordspublicFixture records to be inserted.array
-  $tablepublicFull Table Namestring
Method Summary
-  __construct() publicInstantiate the fixture.
-  _getRecords() protectedConverts the internal records into data used to generate a query.
-  _schemaFromFields() protectedBuild the fixtures table schema from the fields property.
-  _schemaFromImport() protectedBuild fixture schema from a table in another datasource.
-  _schemaFromReflection() protectedBuild fixture schema directly from the datasource
-  _tableFromClass() protectedReturns the table name using the fixture class
-  connection() publicGet the connection name this fixture should be inserted into.
-  create() publicCreate the fixture schema/mapping/definition
-  createConstraints() publicBuild and execute SQL queries necessary to create the constraints for the fixture 
-  drop() publicRun after all tests executed, should remove the table/collection from the connection.
-  dropConstraints() publicBuild and execute SQL queries necessary to drop the constraints for the fixture 
-  getTableSchema() publicGet and set the schema for this fixture.
-  init() publicInitialize the fixture.
-  insert() publicRun before each test is executed.
-  schema() publicGets/Sets the TableSchema instance used by this fixture.
-  setTableSchema() publicGet and set the schema for this fixture.
-  sourceName() publicGet the table/collection name for this fixture.
-  truncate() publicTruncates the current fixture.
Method Detail
__construct()source public
__construct( )
Instantiate the fixture.
Throws
Cake\Core\Exception\Exceptionon invalid datasource usage.
_getRecords()source protected
_getRecords( )
Converts the internal records into data used to generate a query.
Returns
array_schemaFromFields()source protected
_schemaFromFields( )
Build the fixtures table schema from the fields property.
_schemaFromImport()source protected
_schemaFromImport( )
Build fixture schema from a table in another datasource.
Throws
Cake\Core\Exception\Exceptionwhen trying to import from an empty table.
_schemaFromReflection()source protected
_schemaFromReflection( )
Build fixture schema directly from the datasource
Throws
Cake\Core\Exception\Exceptionwhen trying to reflect a table that does not exist
_tableFromClass()source protected
_tableFromClass( )
Returns the table name using the fixture class
Returns
stringconnection()source public
connection( )
Get the connection name this fixture should be inserted into.
Returns
stringImplementation of
Cake\Datasource\FixtureInterface::connection()  create()source 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
booleanTrue on success, false on failure.
Implementation of
Cake\Datasource\FixtureInterface::create()  createConstraints()source 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
booleanon success or if there are no constraints to create, or false on failure
Implementation of
Cake\Datasource\FixtureInterface::createConstraints()  drop()source 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
booleanTrue on success, false on failure.
Implementation of
Cake\Datasource\FixtureInterface::drop()  dropConstraints()source 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
booleanon success or if there are no constraints to drop, or false on failure
Implementation of
Cake\Datasource\FixtureInterface::dropConstraints()  getTableSchema()source public
getTableSchema( )
Get and set the schema for this fixture.
Returns
Cake\Database\Schema\TableSchemaInterface|nullImplementation of
Cake\Database\Schema\TableSchemaAwareInterface::getTableSchema()  init()source public
init( )
Initialize the fixture.
Throws
Cake\ORM\Exception\MissingTableClassExceptionWhen importing from a table that does not exist.
insert()source 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
booleanon success or if there are no records to insert, or false on failure.
Implementation of
Cake\Datasource\FixtureInterface::insert()  schema()source public
schema( Cake\Database\Schema\TableSchema $schema null )
Gets/Sets the TableSchema instance used by this fixture.
Deprecated
3.5.0 Use getTableSchema/setTableSchema instead.Parameters
-  Cake\Database\Schema\TableSchema$schemaoptional null
- The table to set.
Returns
Cake\Database\Schema\TableSchema|nullImplementation of
Cake\Datasource\TableSchemaInterface::schema()  setTableSchema()source 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
Cake\Database\Schema\TableSchemaAwareInterface::setTableSchema()  sourceName()source public
sourceName( )
Get the table/collection name for this fixture.
Returns
stringImplementation of
Cake\Datasource\FixtureInterface::sourceName()  truncate()source public
truncate( Cake\Datasource\ConnectionInterface $db )
Truncates the current fixture.
Parameters
-  Cake\Datasource\ConnectionInterface$db
- A reference to a db instance
Returns
booleanImplementation of
Cake\Datasource\FixtureInterface::truncate()  Properties detail
$fieldssource
public array
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.
[]
$importsource
public array|null
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.
    © 2005–2017 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/3.4/class-Cake.TestSuite.Fixture.TestFixture.html