Class TestFixture
Cake TestFixture is responsible for building and destroying tables to be used during testing.
Property Summary
-
$_schema protected
Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface
The schema for this fixture.
-
$_tableLocator protected
Cake\ORM\Locator\LocatorInterface|null
Table locator instance
-
$connection public
string
Fixture Datasource
-
$defaultTable protected
string|null
This object's default table alias.
-
$records public
array
Fixture records to be inserted.
-
$table public
string
Full Table Name
Method Summary
-
__construct() public
Instantiate the fixture.
-
_getRecords() protected
Converts the internal records into data used to generate a query.
-
_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.
-
fetchTable() public
Convenience method to get a table instance.
-
getTableLocator() public
Gets the table locator.
-
getTableSchema() public
Returns the table schema for this fixture.
-
init() public
Initialize the fixture.
-
insert() public
Run before each test is executed.
-
setTableLocator() public
Sets the table locator.
-
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\CakeException
on invalid datasource usage.
_getRecords() ¶ protected
_getRecords(): array
Converts the internal records into data used to generate a query.
Returns
array
_schemaFromReflection() ¶ protected
_schemaFromReflection(): void
Build fixture schema directly from the datasource
Returns
void
Throws
Cake\Core\Exception\CakeException
when trying to reflect a table that does not exist
_tableFromClass() ¶ protected
_tableFromClass(): string
Returns the table name using the fixture class
Returns
string
connection() ¶ public
connection(): string
Get the connection name this fixture should be inserted into.
Returns
string
fetchTable() ¶ 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
null
then 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\Table
Throws
Cake\Core\Exception\CakeException
If `$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\LocatorInterface
getTableSchema() ¶ public
getTableSchema(): Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface
Returns the table schema for this fixture.
Returns
Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface
init() ¶ public
init(): void
Initialize the fixture.
Returns
void
Throws
Cake\ORM\Exception\MissingTableClassException
When importing from a table that does not exist.
insert() ¶ public
insert(Cake\Datasource\ConnectionInterface $connection): bool
Run before each test is executed.
Should insert all the records into the test database.
Parameters
-
Cake\Datasource\ConnectionInterface
$connection
Returns
bool
setTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator LocatorInterface instance.
Returns
$this
sourceName() ¶ public
sourceName(): string
Get the table/collection name for this fixture.
Returns
string
truncate() ¶ public
truncate(Cake\Datasource\ConnectionInterface $connection): bool
Truncates the current fixture.
Parameters
-
Cake\Datasource\ConnectionInterface
$connection
Returns
bool
Property Detail
$_schema ¶ protected
The schema for this fixture.
Type
Cake\Database\Schema\TableSchemaInterfaceCake\Database\Schema\SqlGeneratorInterface