Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Property Summary
- 
        $_constraints protectedarrayFixture constraints to be created. 
- 
        $_schema protectedCake\Database\Schema\TableSchemaThe schema for this fixture. 
- 
        $_tableLocator protectedCake\ORM\Locator\LocatorInterfaceTable locator instance 
- 
        $connection publicstringFixture Datasource 
- 
        $fields publicarrayFields / Schema for the fixture. 
- 
        $import publicarray|nullConfiguration for importing fixture schema 
- 
        $records publicarrayFixture records to be inserted. 
- 
        $table publicstringFull Table Name 
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 
- 
          getTableLocator() publicGets the table locator. 
- 
          getTableSchema() publicGet and set the schema for this fixture. 
- 
          init() publicInitialize the fixture. 
- 
          insert() publicRun before each test is executed. 
- 
          schema() public deprecatedGets/Sets the TableSchema instance used by this fixture. 
- 
          setTableLocator() publicSets the table locator. 
- 
          setTableSchema() publicGet and set the schema for this fixture. 
- 
          sourceName() publicGet the table/collection name for this fixture. 
- 
          tableLocator() public deprecatedSets the table locator. If no parameters are passed, it will return the currently used locator. 
- 
          truncate() publicTruncates the current fixture. 
Method Detail
__construct() ¶ public
__construct()Instantiate the fixture.
Throws
Cake\Core\Exception\Exceptionon invalid datasource usage.
_getRecords() ¶ protected
_getRecords(): arrayConverts the internal records into data used to generate a query.
Returns
array_schemaFromFields() ¶ protected
_schemaFromFields(): voidBuild the fixtures table schema from the fields property.
Returns
void_schemaFromImport() ¶ protected
_schemaFromImport(): voidBuild fixture schema from a table in another datasource.
Returns
voidThrows
Cake\Core\Exception\Exceptionwhen trying to import from an empty table.
_schemaFromReflection() ¶ protected
_schemaFromReflection(): voidBuild fixture schema directly from the datasource
Returns
voidThrows
Cake\Core\Exception\Exceptionwhen trying to reflect a table that does not exist
_tableFromClass() ¶ protected
_tableFromClass(): stringReturns the table name using the fixture class
Returns
stringconnection() ¶ public
connection(): stringGet the connection name this fixture should be inserted into.
Returns
stringcreate() ¶ public
create(Cake\Datasource\ConnectionInterface $db): boolCreate the fixture schema/mapping/definition
Parameters
- 
                Cake\Datasource\ConnectionInterface$db
Returns
boolcreateConstraints() ¶ public
createConstraints(Cake\Datasource\ConnectionInterface $db): boolBuild and execute SQL queries necessary to create the constraints for the fixture
Parameters
- 
                Cake\Datasource\ConnectionInterface$db
Returns
booldrop() ¶ public
drop(Cake\Datasource\ConnectionInterface $db): boolRun after all tests executed, should remove the table/collection from the connection.
Parameters
- 
                Cake\Datasource\ConnectionInterface$db
Returns
booldropConstraints() ¶ public
dropConstraints(Cake\Datasource\ConnectionInterface $db): boolBuild and execute SQL queries necessary to drop the constraints for the fixture
Parameters
- 
                Cake\Datasource\ConnectionInterface$db
Returns
boolgetTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterfaceGets the table locator.
Returns
Cake\ORM\Locator\LocatorInterfacegetTableSchema() ¶ public
getTableSchema(): Cake\Database\Schema\TableSchemaInterface|nullGet and set the schema for this fixture.
Returns
Cake\Database\Schema\TableSchemaInterface|nullinit() ¶ public
init(): voidInitialize the fixture.
Returns
voidThrows
Cake\ORM\Exception\MissingTableClassExceptionWhen importing from a table that does not exist.
insert() ¶ public
insert(Cake\Datasource\ConnectionInterface $db): Cake\Database\StatementInterface|boolRun before each test is executed.
Should insert all the records into the test database.
Parameters
- 
                Cake\Datasource\ConnectionInterface$db
Returns
Cake\Database\StatementInterface|boolschema() ¶ public
schema(Cake\Database\Schema\TableSchema|null $schema = null): Cake\Database\Schema\TableSchema|nullGets/Sets the TableSchema instance used by this fixture.
Parameters
- 
                Cake\Database\Schema\TableSchema|null$schema optional
- The table to set. 
Returns
Cake\Database\Schema\TableSchema|nullsetTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $thisSets the table locator.
Parameters
- 
                Cake\ORM\Locator\LocatorInterface$tableLocator
- LocatorInterface instance. 
Returns
$thissetTableSchema() ¶ public
setTableSchema(DatabaseTableSchemaInterface $schema): $thisGet and set the schema for this fixture.
Parameters
- 
                DatabaseTableSchemaInterface$schema
Returns
$thissourceName() ¶ public
sourceName(): stringGet the table/collection name for this fixture.
Returns
stringtableLocator() ¶ public
tableLocator(Cake\ORM\Locator\LocatorInterface|null $tableLocator = null): Cake\ORM\Locator\LocatorInterfaceSets the table locator. If no parameters are passed, it will return the currently used locator.
Parameters
- 
                Cake\ORM\Locator\LocatorInterface|null$tableLocator optional
- LocatorInterface instance. 
Returns
Cake\ORM\Locator\LocatorInterfacetruncate() ¶ public
truncate(Cake\Datasource\ConnectionInterface $db): boolTruncates the current fixture.
Parameters
- 
                Cake\Datasource\ConnectionInterface$db
Returns
boolProperty Detail
$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