Skip to content

Commit d77af96

Browse files
mad-brillerondrejmirtes
authored andcommitted
Fix empty @Covers annotation causing a crash.
1 parent bf47c49 commit d77af96

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/Rules/PHPUnit/CoversHelper.php

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ public function processCovers(
9595
))->build();
9696
}
9797
} else {
98+
if ($covers === '') {
99+
$errors[] = RuleErrorBuilder::message('@covers value does not specify anything.')->build();
100+
101+
return $errors;
102+
}
103+
98104
if (!isset($method) && $this->reflectionProvider->hasFunction(new Name($covers, []), null)) {
99105
return $errors;
100106
}

tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function testRule(): void
3636
'@covers value \Not\A\Class references an invalid class or function.',
3737
31,
3838
],
39+
[
40+
'@covers value does not specify anything.',
41+
43,
42+
],
3943
]);
4044
}
4145

tests/Rules/PHPUnit/data/class-coverage.php

+7
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ function testable(): void
3636
{
3737

3838
}
39+
40+
/**
41+
* @covers
42+
*/
43+
class CoversNothing extends \PHPUnit\Framework\TestCase
44+
{
45+
}

0 commit comments

Comments
 (0)