InteractsWithParallelDatabase
trait InteractsWithParallelDatabase
Provides per-worker database isolation for parallel testing.
Two-phase approach:
- Config rewrite (early, in CreatesApplication): rewrites the default connection's database name to {database}test{token} before defineEnvironment() runs, so custom connections derived from the default connection inherit the correct database name.
- Database creation (before Testbench database requirements and in database traits): ensures the per-worker database exists, creating it on demand.
In-memory SQLite databases are skipped — each worker process gets its own memory space naturally.
Methods
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.
Details
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.
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.
at line 157
protected bool
shouldManageParallelDatabase(mixed $driver, string $database)
Determine if the database should be managed for parallel testing.
at line 184
protected string
parallelTestDatabase(string $database, string $token)
Get the per-worker test database name.