Skip to content

Commit

Permalink
Add way to call hooks for tests running in coroutines (#7151)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoskubis authored Nov 20, 2024
1 parent 3cba517 commit d703d28
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Concerns/RunTestsInCoroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ final protected function runTestsInCoroutine(...$arguments)
/* @phpstan-ignore-next-line */
\Swoole\Coroutine\run(function () use (&$testResult, &$exception, $arguments) {
try {
$this->invokeBeforeHookMethods();
$testResult = $this->{$this->realTestName}(...$arguments);
} catch (Throwable $e) {
$exception = $e;
} finally {
$this->invokeAfterHookMethods();
Timer::clearAll();
CoordinatorManager::until(Constants::WORKER_EXIT)->resume();
}
Expand All @@ -62,4 +64,18 @@ final protected function runTest(): mixed

return parent::runTest();
}

private function invokeBeforeHookMethods(): void
{
if (method_exists($this, 'beforeTestInCoroutine')) {
call_user_func([$this, 'beforeTestInCoroutine']);
}
}

private function invokeAfterHookMethods(): void
{
if (method_exists($this, 'afterTestInCoroutine')) {
call_user_func([$this, 'afterTestInCoroutine']);
}
}
}

0 comments on commit d703d28

Please sign in to comment.