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 $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.

Methods

void
setUpTheTestEnvironment()

Set up the test environment.

void
tearDownTheTestEnvironment()

Clean up the testing environment before the next test.

array
setUpTraits()

Boot the testing helper traits.

void
setUpDatabaseTraits(array $uses)

Set up database-related testing traits.

static void
tearDownAfterClassUsingTestCase()

Clean up the testing environment before the next test case.

afterApplicationCreated(callable $callback)

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

beforeApplicationDestroyed(callable $callback)

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

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 62
protected void setUpTheTestEnvironment()

internal  
 

Set up the test environment.

Return Value

void

at line 101
protected void tearDownTheTestEnvironment()

internal  
 

Clean up the testing environment before the next test.

Return Value

void

Exceptions

Throwable

at line 180
protected array setUpTraits()

Boot the testing helper traits.

Return Value

array

at line 227
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 251
static void tearDownAfterClassUsingTestCase()

internal  
 

Clean up the testing environment before the next test case.

Return Value

void

at line 264
afterApplicationCreated(callable $callback)

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

Parameters

callable $callback

at line 276
protected beforeApplicationDestroyed(callable $callback)

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

Parameters

callable $callback

at line 284
protected callBeforeApplicationDestroyedCallbacks()

Execute the application's pre-destruction callbacks.

at line 305
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 will then copy from non-coroutine context via copyFromNonCoroutine().

Return Value

void

at line 316
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