Skip to content

Commit

Permalink
pass Job to callbacks in Job::$onAfterExecute
Browse files Browse the repository at this point in the history
  • Loading branch information
konecnyjakub committed Dec 20, 2024
1 parent 8f17f3e commit 0f2b93e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function getException(): ?\Throwable
private function onAfterExecute(): void
{
foreach ($this->onAfterExecute as $callback) {
$callback();
$callback($this);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
},
Expand Down Expand Up @@ -184,7 +185,6 @@ protected function runJob(Job $job): string
$this->setUp();
}
$job->execute();
$job->totalAssertions = $this->getCounter();
if (!$job->skip) {
$this->tearDown();
}
Expand Down

0 comments on commit 0f2b93e

Please sign in to comment.