Class ConnectionHelper
Helper for managing test connections
Method Summary
-
addTestAliases() public
Adds
test_<connection name>
aliases for all non-test connections. -
dropTables() public
Drops all tables.
-
enableQueryLogging() public
Enables query logging for all database connections.
-
runWithoutConstraints() public
Runs callback with constraints disabled correctly per-database
-
truncateTables() public
Truncates all tables.
Method Detail
addTestAliases() ¶ public
addTestAliases(): void
Adds test_<connection name>
aliases for all non-test connections.
This forces all models to use the test connection instead. For example,
if a model is confused to use connection files
then it will be aliased
to test_files
.
The default
connection is aliased to test
.
Returns
void
dropTables() ¶ public
dropTables(string $connectionName, array<string>|null $tables = null): void
Drops all tables.
Parameters
-
string
$connectionName Connection name
-
array<string>|null
$tables optional List of tables names or null for all.
Returns
void
enableQueryLogging() ¶ public
enableQueryLogging(array<int, string>|null $connections = null): void
Enables query logging for all database connections.
Parameters
-
array<int, string>|null
$connections optional Connection names or null for all.
Returns
void
runWithoutConstraints() ¶ public
runWithoutConstraints(Cake\Database\Connection $connection, Closure $callback): void
Runs callback with constraints disabled correctly per-database
Parameters
-
Cake\Database\Connection
$connection Database connection
-
Closure
$callback callback
Returns
void
truncateTables() ¶ public
truncateTables(string $connectionName, array<string>|null $tables = null): void
Truncates all tables.
Parameters
-
string
$connectionName Connection name
-
array<string>|null
$tables optional List of tables names or null for all.
Returns
void