On this page
Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
- Cake\TestSuite\Fixture\TestFixture implements Cake\Datasource\FixtureInterface
Method Detail
__constructsource public
__construct( )Instantiate the fixture.
Throws
Cake\Core\Exception\Exceptionon invalid datasource usage.
_getRecordssource protected
_getRecords( )Converts the internal records into data used to generate a query.
Returns
arrayarray
_schemaFromFieldssource protected
_schemaFromFields( )Build the fixtures table schema from the fields property.
_schemaFromImportsource protected
_schemaFromImport( )Build fixture schema from a table in another datasource.
Throws
Cake\Core\Exception\Exceptionwhen trying to import from an empty table.
connectionsource public
connection( )Get the connection name this fixture should be inserted into.
Returns
stringstring
Implementation of
Cake\Datasource\FixtureInterface::connection()
  createsource 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()
  createConstraintssource 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()
  dropsource 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()
  dropConstraintssource 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()
  initsource public
init( )Initialize the fixture.
Throws
Cake\ORM\Exception\MissingTableClassExceptionWhen importing from a table that does not exist.
insertsource 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()
  schemasource public
schema( Cake\Database\Schema\Table $schema null )Get/Set the Cake\Database\Schema\Table instance used by this fixture.
Parameters
- Cake\Database\Schema\Table- $schemaoptional null
- The table to set.
Returns
Cake\Database\Schema\Table|null\Cake\Database\Schema\Table|null
sourceNamesource public
sourceName( )Get the table/collection name for this fixture.
Returns
stringstring
Implementation of
Cake\Datasource\FixtureInterface::sourceName()
  truncatesource public
truncate( Cake\Datasource\ConnectionInterface $db )Truncates the current fixture.
Parameters
- Cake\Datasource\ConnectionInterface- $db
- A reference to a db instance
Returns
booleanbool
Implementation of
Cake\Datasource\FixtureInterface::truncate()
  Properties summary
$_schemasource
protected Cake\Database\Schema\Table
The Cake\Database\Schema\Table for this fixture.
$fieldssource
public array
Fields / Schema for the fixture.
This array should be compatible with Cake\Database\Schema\Table. 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.
null© 2005–2016 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.
 http://api.cakephp.org/3.1/class-Cake.TestSuite.Fixture.TestFixture.html