trait DatabaseMigrations

Traits

Provides per-worker database isolation for parallel testing.

Properties

static protected string|null $originalDatabaseName

The original database name before parallel suffixing.

from  InteractsWithParallelDatabase

Methods

array
migrateFreshUsing()

The parameters that should be used when running "migrate:fresh".

bool
shouldDropViews()

Determine if views should be dropped when refreshing the database.

bool
shouldDropTypes()

Determine if types should be dropped when refreshing the database.

bool
shouldSeed()

Determine if the seed task should be run when refreshing the database.

mixed
seeder()

Determine the specific seeder class that should be used when refreshing the database.

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.

void
runDatabaseMigrations()

Define hooks to migrate the database before and after each test.

void
refreshModelBootedStates()

Refresh the model booted states.

void
beforeRefreshingDatabase()

Perform any work that should take place before the database has started refreshing.

void
afterRefreshingDatabase()

Perform any work that should take place once the database has finished refreshing.

Details

protected array migrateFreshUsing()

The parameters that should be used when running "migrate:fresh".

Return Value

array

protected bool shouldDropViews()

Determine if views should be dropped when refreshing the database.

Return Value

bool

protected bool shouldDropTypes()

Determine if types should be dropped when refreshing the database.

Return Value

bool

protected bool shouldSeed()

Determine if the seed task should be run when refreshing the database.

Return Value

bool

protected mixed seeder()

Determine the specific seeder class that should be used when refreshing the database.

Return Value

mixed

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

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.

Return Value

void

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

protected string parallelTestDatabase(string $database, string $token)

Get the per-worker test database name.

Parameters

string $database
string $token

Return Value

string

at line 19
void runDatabaseMigrations()

Define hooks to migrate the database before and after each test.

Return Value

void

at line 46
protected void refreshModelBootedStates()

Refresh the model booted states.

Clears the static booted model tracking so that models re-register their event listeners with the current event dispatcher. This is necessary when Event::fake() creates a new EventFake, otherwise model event callbacks point to the old dispatcher.

Return Value

void

at line 54
protected void beforeRefreshingDatabase()

Perform any work that should take place before the database has started refreshing.

Return Value

void

at line 62
protected void afterRefreshingDatabase()

Perform any work that should take place once the database has finished refreshing.

Return Value

void