Skip to content

Commit d703d28

Browse files
authored
Add way to call hooks for tests running in coroutines (#7151)
1 parent 3cba517 commit d703d28

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Concerns/RunTestsInCoroutine.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ final protected function runTestsInCoroutine(...$arguments)
3737
/* @phpstan-ignore-next-line */
3838
\Swoole\Coroutine\run(function () use (&$testResult, &$exception, $arguments) {
3939
try {
40+
$this->invokeBeforeHookMethods();
4041
$testResult = $this->{$this->realTestName}(...$arguments);
4142
} catch (Throwable $e) {
4243
$exception = $e;
4344
} finally {
45+
$this->invokeAfterHookMethods();
4446
Timer::clearAll();
4547
CoordinatorManager::until(Constants::WORKER_EXIT)->resume();
4648
}
@@ -62,4 +64,18 @@ final protected function runTest(): mixed
6264

6365
return parent::runTest();
6466
}
67+
68+
private function invokeBeforeHookMethods(): void
69+
{
70+
if (method_exists($this, 'beforeTestInCoroutine')) {
71+
call_user_func([$this, 'beforeTestInCoroutine']);
72+
}
73+
}
74+
75+
private function invokeAfterHookMethods(): void
76+
{
77+
if (method_exists($this, 'afterTestInCoroutine')) {
78+
call_user_func([$this, 'afterTestInCoroutine']);
79+
}
80+
}
6581
}

0 commit comments

Comments
 (0)