DatabaseTruncation
trait DatabaseTruncation
This concern may be combined with RefreshDatabase or DatabaseTransactions; each trait should manage its own connections. It cannot be combined with DatabaseMigrations or LazilyRefreshDatabase.
Traits
Provides per-worker database isolation for parallel testing.
Properties
| static protected array | $allTables | The cached names of the database tables for each connection. |
Methods
The parameters that should be used when running "migrate:fresh".
Determine if views should be dropped when refreshing the database.
Determine if types should be dropped when refreshing the database.
Determine if the seed task should be run when refreshing the database.
Determine the specific seeder class that should be used when refreshing the database.
Rewrite the default connection's database name for parallel testing.
Ensure the per-worker database exists, creating it if needed.
Determine if the database should be managed for parallel testing.
Get the per-worker test database name.
Truncate the database tables for all configured connections.
Restore the in-memory databases between tests.
Cache the in-memory databases after migration.
Determine if any connection being truncated uses an in-memory database.
Determine if an in-memory database being truncated is missing its cached PDO.
Determine if the given connection uses an in-memory database.
Truncate the database tables for all configured connections.
Truncate the database tables for the given database connection.
Get all the tables that belong to the connection.
Determine if a table exists in the given list, with or without its schema.
The database connections that should have their tables truncated.
Get the tables that should be truncated.
Get the tables that should not be truncated.
Perform any work that should take place before the database has started truncating.
Perform any work that should take place once the database has finished truncating.
Details
in
CanConfigureMigrationCommands at line 16
protected array
migrateFreshUsing()
The parameters that should be used when running "migrate:fresh".
in
CanConfigureMigrationCommands at line 32
protected bool
shouldDropViews()
Determine if views should be dropped when refreshing the database.
in
CanConfigureMigrationCommands at line 40
protected bool
shouldDropTypes()
Determine if types should be dropped when refreshing the database.
in
CanConfigureMigrationCommands at line 48
protected bool
shouldSeed()
Determine if the seed task should be run when refreshing the database.
in
CanConfigureMigrationCommands at line 64
protected mixed
seeder()
Determine the specific seeder class that should be used when refreshing the database.
in
InteractsWithParallelDatabase at line 42
protected void
configureParallelDatabaseName(mixed $app)
Rewrite the default connection's database name for parallel testing.
Config-only — does not create connections or purge pools. Called early in CreatesApplication (after config is loaded, before defineEnvironment) so that custom connections derived from the default connection inherit the per-worker database name.
No-op when not running in parallel or when using in-memory SQLite.
in
InteractsWithParallelDatabase at line 95
protected void
ensureParallelDatabaseExists()
Ensure the per-worker database exists, creating it if needed.
Called before Testbench database requirements and from database testing traits (RefreshDatabase, DatabaseMigrations, DatabaseTruncation, DatabaseTransactions) after the app is booted and connections are available. The config has already been rewritten by configureParallelDatabaseName().
No-op when not running in parallel or when using in-memory SQLite.
in
InteractsWithParallelDatabase at line 157
protected bool
shouldManageParallelDatabase(mixed $driver, string $database)
Determine if the database should be managed for parallel testing.
in
InteractsWithParallelDatabase at line 184
protected string
parallelTestDatabase(string $database, string $token)
Get the per-worker test database name.
at line 36
protected void
truncateDatabaseTables()
Truncate the database tables for all configured connections.
at line 101
protected void
restoreInMemoryDatabases()
Restore the in-memory databases between tests.
at line 131
protected void
cacheInMemoryDatabases()
Cache the in-memory databases after migration.
at line 154
protected bool
usingInMemoryDatabasesForTruncation()
Determine if any connection being truncated uses an in-memory database.
at line 168
protected bool
hasMissingInMemoryDatabaseForTruncation()
Determine if an in-memory database being truncated is missing its cached PDO.
at line 189
protected bool
usingInMemoryDatabaseForTruncation(string|null $name)
Determine if the given connection uses an in-memory database.
at line 202
protected void
truncateTablesForAllConnections()
Truncate the database tables for all configured connections.
at line 219
protected void
truncateTablesForConnection(ConnectionInterface $connection, string|null $name)
Truncate the database tables for the given database connection.
at line 254
protected array
getAllTablesForConnection(ConnectionInterface $connection, string|null $name)
Get all the tables that belong to the connection.
at line 268
protected bool
tableExistsIn(array $table, array $tables)
Determine if a table exists in the given list, with or without its schema.
at line 278
protected array
connectionsToTruncate()
The database connections that should have their tables truncated.
at line 288
protected array|null
tablesToTruncate(ConnectionInterface $connection, string|null $connectionName)
Get the tables that should be truncated.
at line 298
protected array
exceptTables(ConnectionInterface $connection, string|null $connectionName)
Get the tables that should not be truncated.
at line 314
protected void
beforeTruncatingDatabase()
Perform any work that should take place before the database has started truncating.
at line 321
protected void
afterTruncatingDatabase()
Perform any work that should take place once the database has finished truncating.