trait InteractsWithTestCaseLifecycle

Properties

protected Application|null $app

The application instance.

protected array $afterApplicationCreatedCallbacks

The callbacks that should be run after the application is created.

protected array $afterApplicationRefreshedCallbacks

The callbacks that should be run after the application is refreshed.

protected array $beforeApplicationDestroyedCallbacks

The callbacks that should be run before the application is destroyed.

protected Throwable|null $callbackException

The exception thrown while running an application destruction callback.

protected bool $setUpHasRun

Indicates if we have made it through the base setUp function.

protected bool $afterApplicationRefreshedCallbacksStarted

Indicates if the application refreshed callbacks have started running.

Methods

void
setUpTheTestEnvironment()

Set up the test environment.

void
tearDownTheTestEnvironment()

Clean up the testing environment before the next test.

void
flushState()

Reset static state between test executions.

array
setUpTraits()

Boot the testing helper traits.

bool
setUpTheTestEnvironmentTraitToBeIgnored(string $use)

Determine if the trait should be skipped when setting up the test environment.

void
setUpDatabaseTraits(array $uses)

Set up database-related testing traits.

void
forgetStaleMigrationState(array $uses)

Forget retained migration state when a selected in-memory database is missing.

static void
tearDownAfterClassUsingTestCase()

Clean up the testing environment before the next test case.

void
afterApplicationRefreshed(callable $callback)

Register a callback to be run after the application is refreshed.

void
afterApplicationCreated(callable $callback)

Register a callback to be run after the application is created.

void
beforeApplicationDestroyed(callable $callback)

Register a callback to be run before the application is destroyed.

void
callBeforeApplicationDestroyedCallbacks()

Execute the application's pre-destruction callbacks.

void
preserveTransactionContext()

Preserve transaction manager context for the test coroutine.

void
runInCoroutine(callable $callback)

Ensure callback is executed in coroutine.

Details

at line 72
protected void setUpTheTestEnvironment()

internal  
 

Set up the test environment.

Return Value

void

at line 116
protected void tearDownTheTestEnvironment()

internal  
 

Clean up the testing environment before the next test.

Return Value

void

Exceptions

Throwable

at line 187
protected void flushState()

Reset static state between test executions.

Return Value

void

at line 196
protected array setUpTraits()

Boot the testing helper traits.

Return Value

array

at line 246
protected bool setUpTheTestEnvironmentTraitToBeIgnored(string $use)

Determine if the trait should be skipped when setting up the test environment.

Parameters

string $use

Return Value

bool

at line 257
protected void setUpDatabaseTraits(array $uses)

Set up database-related testing traits.

Override this method to customize database trait initialization order, e.g. to process test attributes before migrations run.

Parameters

array $uses

Return Value

void

at line 281
protected void forgetStaleMigrationState(array $uses)

Forget retained migration state when a selected in-memory database is missing.

Parameters

array $uses

Return Value

void

at line 301
static void tearDownAfterClassUsingTestCase()

internal  
 

Clean up the testing environment before the next test case.

Return Value

void

at line 310
void afterApplicationRefreshed(callable $callback)

Register a callback to be run after the application is refreshed.

The callbacks run before the test case's traits are set up, and again for each reloaded application.

Parameters

callable $callback

Return Value

void

at line 322
void afterApplicationCreated(callable $callback)

Register a callback to be run after the application is created.

Parameters

callable $callback

Return Value

void

at line 334
protected void beforeApplicationDestroyed(callable $callback)

Register a callback to be run before the application is destroyed.

Parameters

callable $callback

Return Value

void

at line 342
protected void callBeforeApplicationDestroyedCallbacks()

Execute the application's pre-destruction callbacks.

Return Value

void

at line 364
protected void preserveTransactionContext()

Preserve transaction manager context for the test coroutine.

RefreshDatabase and DatabaseTransactions store transaction state in Context. Since setUpTraits runs in a temporary coroutine (separate from the test method's coroutine), we must copy this state to non-coroutine context. The test coroutine restores the same transaction state explicitly; normal context copying omits it so child coroutines cannot inherit their parent's transactions.

Return Value

void

at line 375
protected void runInCoroutine(callable $callback)

Ensure callback is executed in coroutine.

Exceptions are captured and re-thrown outside the coroutine context so they propagate correctly to PHPUnit (e.g., for markTestSkipped).

Parameters

callable $callback

Return Value

void