RunTestsInCoroutine
trait RunTestsInCoroutine
Properties
| protected bool | $runTestsInCoroutine | ||
| protected bool | $copyNonCoroutineContext | ||
| protected Throwable|null | $exceptionOutlivedByChildCoroutines | The exception the test threw before its child coroutines reached the time limit. |
Methods
Invoke the test method inside a Swoole coroutine container.
Enforce PHPUnit's deadline while the test or its children are suspended.
Fail a test whose expected exception was followed by child coroutines reaching the time limit.
Determine whether tests run in a coroutine.
Determine if framework lifecycle hooks should run for this test.
Run trait and test setup hooks in the test coroutine.
Run test and trait teardown hooks while capturing failures.
Clear transaction context from non-coroutine storage before test starts.
Clean up Context keys that cause test pollution.
Details
at line 47
protected mixed
invokeTestMethod(string $methodName, array $testArguments)
Invoke the test method inside a Swoole coroutine container.
Uses PHPUnit 13's official extension point for customizing test method invocation. When coroutines are enabled and we're not already inside one, the test method runs inside Hypervel's coroutine container with full lifecycle management (context copying, setup/teardown hooks, cleanup).
at line 132
protected void
enforceCoroutineTestTimeLimit(TimeoutException|null $timeoutException, bool $rootCompleted)
Enforce PHPUnit's deadline while the test or its children are suspended.
at line 208
protected void
assertChildCoroutinesFinishedBeforeTimeLimit()
Fail a test whose expected exception was followed by child coroutines reaching the time limit.
at line 223
protected bool
runsTestsInCoroutine()
Determine whether tests run in a coroutine.
at line 231
protected bool
shouldBootFrameworkForTest()
Determine if framework lifecycle hooks should run for this test.
at line 239
protected void
invokeSetupInCoroutine()
Run trait and test setup hooks in the test coroutine.
at line 257
protected void
invokeTearDownInCoroutine(callable $capture)
Run test and trait teardown hooks while capturing failures.
at line 280
protected void
clearNonCoroutineTransactionContext()
Clear transaction context from non-coroutine storage before test starts.
RefreshDatabase starts its wrapper transaction in setUp() (outside coroutine), storing it in nonCoroutineContext. We must preserve this data for copying into the coroutine. Only clear if there are no pending transactions (meaning any data is stale from a previous test that didn't clean up properly).
at line 296
protected void
cleanupTestContext()
Clean up Context keys that cause test pollution.
Only forgets specific keys known to leak between tests. Does not use CoroutineContext::flush() because that would flush data needed by defer callbacks (e.g., Redis connections waiting to be released).