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 (later, in database traits): ensures the per-worker database exists, creating it on demand if needed.
In-memory SQLite databases are skipped — each worker process gets its own memory space naturally.
Properties
| static protected string|null | $originalDatabaseName | The original database name before parallel suffixing. |
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 45
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 86
protected void
ensureParallelDatabaseExists()
Ensure the per-worker database exists, creating it if needed.
Called from database testing traits (RefreshDatabase, DatabaseMigrations, 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 132
protected bool
shouldManageParallelDatabase(mixed $driver, string $database)
Determine if the database should be managed for parallel testing.
at line 159
protected string
parallelTestDatabase(string $database, string $token)
Get the per-worker test database name.