trait InteractsWithParallelDatabase

Provides per-worker database isolation for parallel testing.

Two-phase approach:

  1. 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.
  2. 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

void
configureParallelDatabaseName(mixed $app)

Rewrite the default connection's database name for parallel testing.

void
ensureParallelDatabaseExists()

Ensure the per-worker database exists, creating it if needed.

bool
shouldManageParallelDatabase(mixed $driver, string $database)

Determine if the database should be managed for parallel testing.

string
parallelTestDatabase(string $database, string $token)

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.

Parameters

mixed $app

Return Value

void

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.

Return Value

void

at line 157
protected bool shouldManageParallelDatabase(mixed $driver, string $database)

Determine if the database should be managed for parallel testing.

Parameters

mixed $driver
string $database

Return Value

bool

at line 184
protected string parallelTestDatabase(string $database, string $token)

Get the per-worker test database name.

Parameters

string $database
string $token

Return Value

string