Skip to content

Commit

Permalink
Fix empty @Covers annotation causing a crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
mad-briller authored and ondrejmirtes committed Feb 9, 2023
1 parent bf47c49 commit d77af96
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Rules/PHPUnit/CoversHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public function processCovers(
))->build();
}
} else {
if ($covers === '') {
$errors[] = RuleErrorBuilder::message('@covers value does not specify anything.')->build();

return $errors;
}

if (!isset($method) && $this->reflectionProvider->hasFunction(new Name($covers, []), null)) {
return $errors;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function testRule(): void
'@covers value \Not\A\Class references an invalid class or function.',
31,
],
[
'@covers value does not specify anything.',
43,
],
]);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Rules/PHPUnit/data/class-coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ function testable(): void
{

}

/**
* @covers
*/
class CoversNothing extends \PHPUnit\Framework\TestCase
{
}

0 comments on commit d77af96

Please sign in to comment.