Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Property Summary
- $_constraints protected
array<string, mixed>Fixture constraints to be created.
- $_schema protected
Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterfaceThe schema for this fixture.
- $_tableLocator protected
Cake\ORM\Locator\LocatorInterface|nullTable locator instance
- $connection public
stringFixture Datasource
- $defaultTable protected
string|nullThis object's default table alias.
- $fields public
arrayFields / Schema for the fixture.
- $import public
array|nullConfiguration for importing fixture schema
- $records public
arrayFixture records to be inserted.
- $table public
stringFull Table Name
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
-
fetchTable() public
Convenience method to get a table instance.
-
getTableLocator() public
Gets the table locator.
-
getTableSchema() public
Get and set the schema for this fixture.
-
init() public
Initialize the fixture.
-
insert() public
Run before each test is executed.
-
setTableLocator() public
Sets the table locator.
-
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
__construct() public
__construct()
Instantiate the fixture.
Throws
Cake\Core\Exception\CakeExceptionon invalid datasource usage.
_getRecords() protected
_getRecords(): array
Converts the internal records into data used to generate a query.
Returns
array_schemaFromFields() protected
_schemaFromFields(): void
Build the fixtures table schema from the fields property.
Returns
void_schemaFromImport() protected
_schemaFromImport(): void
Build fixture schema from a table in another datasource.
Returns
voidThrows
Cake\Core\Exception\CakeExceptionwhen trying to import from an empty table.
_schemaFromReflection() protected
_schemaFromReflection(): void
Build fixture schema directly from the datasource
Returns
voidThrows
Cake\Core\Exception\CakeExceptionwhen trying to reflect a table that does not exist
_tableFromClass() protected
_tableFromClass(): string
Returns the table name using the fixture class
Returns
stringconnection() public
connection(): string
Get the connection name this fixture should be inserted into.
Returns
stringcreate() public
create(Cake\Datasource\ConnectionInterface $connection): bool
Create the fixture schema/mapping/definition
Parameters
-
Cake\Datasource\ConnectionInterface$connection
Returns
boolcreateConstraints() public
createConstraints(Cake\Datasource\ConnectionInterface $connection): bool
Build and execute SQL queries necessary to create the constraints for the fixture
Parameters
-
Cake\Datasource\ConnectionInterface$connection
Returns
booldrop() public
drop(Cake\Datasource\ConnectionInterface $connection): bool
Run after all tests executed, should remove the table/collection from the connection.
Parameters
-
Cake\Datasource\ConnectionInterface$connection
Returns
booldropConstraints() public
dropConstraints(Cake\Datasource\ConnectionInterface $connection): bool
Build and execute SQL queries necessary to drop the constraints for the fixture
Parameters
-
Cake\Datasource\ConnectionInterface$connection
Returns
boolfetchTable() public
fetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table
Convenience method to get a table instance.
Parameters
-
string|null$alias optional The alias name you want to get. Should be in CamelCase format. If
nullthen the value of $defaultTable property is used.-
array<string, mixed>$options optional The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Returns
Cake\ORM\TableThrows
Cake\Core\Exception\CakeExceptionIf `$alias` argument and `$defaultTable` property both are `null`.
See Also
getTableLocator() public
getTableLocator(): Cake\ORM\Locator\LocatorInterface
Gets the table locator.
Returns
Cake\ORM\Locator\LocatorInterfacegetTableSchema() public
getTableSchema(): Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface
Get and set the schema for this fixture.
Returns
Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterfaceinit() public
init(): void
Initialize the fixture.
Returns
voidThrows
Cake\ORM\Exception\MissingTableClassExceptionWhen importing from a table that does not exist.
insert() public
insert(Cake\Datasource\ConnectionInterface $connection): Cake\Database\StatementInterface|bool
Run before each test is executed.
Should insert all the records into the test database.
Parameters
-
Cake\Datasource\ConnectionInterface$connection
Returns
Cake\Database\StatementInterface|boolsetTableLocator() public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface$tableLocator LocatorInterface instance.
Returns
$thissetTableSchema() public
setTableSchema(Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface $schema): $this
Get and set the schema for this fixture.
Parameters
-
Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface$schema
Returns
$thissourceName() public
sourceName(): string
Get the table/collection name for this fixture.
Returns
stringtruncate() public
truncate(Cake\Datasource\ConnectionInterface $connection): bool
Truncates the current fixture.
Parameters
-
Cake\Datasource\ConnectionInterface$connection
Returns
boolProperty Detail
$_constraints protected
Fixture constraints to be created.
Type
array<string, mixed>$_schema protected
The schema for this fixture.
Type
Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface$_tableLocator protected
Table locator instance
Type
Cake\ORM\Locator\LocatorInterface|null$connection public
Fixture Datasource
Type
string$defaultTable protected
This object's default table alias.
Type
string|null$fields public
Fields / Schema for the fixture.
This array should be compatible with {@link \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.4/class-Cake.TestSuite.Fixture.TestFixture.html