From 0f2b93ec1a2c6ae03dd28063e5a63858fa4e112c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kone=C4=8Dn=C3=BD?= Date: Fri, 20 Dec 2024 16:19:26 +0100 Subject: [PATCH] pass Job to callbacks in Job::$onAfterExecute --- CHANGELOG.md | 1 + src/Job.php | 2 +- src/TestCase.php | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b87daa7..486ad70c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ Version 7.0.0+dev - filename of generated code coverage report is now shown in console (if a report is generated and is saved into a file) +- callbacks in Job::$onAfterExecute receive Job as first parameter Version 7.0.0 - BC break: used interfaces for data provider and skip checker in TestCase diff --git a/src/Job.php b/src/Job.php index 173a39c7..d0dd3131 100644 --- a/src/Job.php +++ b/src/Job.php @@ -78,7 +78,7 @@ protected function getException(): ?\Throwable private function onAfterExecute(): void { foreach ($this->onAfterExecute as $callback) { - $callback(); + $callback($this); } } diff --git a/src/TestCase.php b/src/TestCase.php index 27cb8e8f..b931fd19 100644 --- a/src/TestCase.php +++ b/src/TestCase.php @@ -80,8 +80,9 @@ protected function getJobs(): array "params" => [], "skip" => $this->skipChecker->shouldSkip(static::class, $method), "onAfterExecute" => [ - function (): void { - if ($this->getCounter() === 0) { + function (Job $job): void { + $job->totalAssertions = $this->getCounter(); + if ($job->totalAssertions === 0) { echo "Warning: No assertions were performed.\n"; } }, @@ -184,7 +185,6 @@ protected function runJob(Job $job): string $this->setUp(); } $job->execute(); - $job->totalAssertions = $this->getCounter(); if (!$job->skip) { $this->tearDown(); }