UnitTestCase
abstract class UnitTestCase extends TestCase
Base test case for coroutine-aware tests that do not boot an application.
Use Hypervel\Testbench\TestCase when a test needs an application.
Traits
Properties
| protected bool | $runTestsInCoroutine | from RunTestsInCoroutine | |
| protected bool | $copyNonCoroutineContext | from RunTestsInCoroutine |
Methods
Set an environment variable for the current PHP process.
Unset an environment variable for the current PHP process.
Run a callback with a temporary environment variable value.
Run a callback with temporary environment variable values.
Tear down the testing environment using Mockery.
Invoke the test method inside a Swoole coroutine container.
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 the testing environment after the test.
Flush the global exception-handler state.
Details
in
InteractsWithEnvironment at line 15
protected void
setEnvironmentValue(string $key, string $value)
Set an environment variable for the current PHP process.
in
InteractsWithEnvironment at line 27
protected void
unsetEnvironmentValue(string $key)
Unset an environment variable for the current PHP process.
in
InteractsWithEnvironment at line 38
protected mixed
withEnvironmentValue(string $key, string|null $value, Closure $callback)
Run a callback with a temporary environment variable value.
in
InteractsWithEnvironment at line 48
protected mixed
withEnvironmentValues(array $values, Closure $callback)
Run a callback with temporary environment variable values.
in
InteractsWithMockery at line 15
protected void
tearDownTheTestEnvironmentUsingMockery()
Tear down the testing environment using Mockery.
in
RunTestsInCoroutine at line 34
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).
in
RunTestsInCoroutine at line 90
protected bool
runsTestsInCoroutine()
Determine whether tests run in a coroutine.
in
RunTestsInCoroutine at line 98
protected bool
shouldBootFrameworkForTest()
Determine if framework lifecycle hooks should run for this test.
in
RunTestsInCoroutine at line 106
protected void
invokeSetupInCoroutine()
Run trait and test setup hooks in the test coroutine.
in
RunTestsInCoroutine at line 124
protected void
invokeTearDownInCoroutine(callable $capture)
Run test and trait teardown hooks while capturing failures.
in
RunTestsInCoroutine at line 147
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).
in
RunTestsInCoroutine at line 163
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).
at line 28
protected void
tearDown()
Clean up the testing environment after the test.
at line 53
protected void
flushExceptionHandlerState()
Flush the global exception-handler state.