diff --git a/src/Rules/PHPUnit/CoversHelper.php b/src/Rules/PHPUnit/CoversHelper.php index a96257f..792fcc1 100644 --- a/src/Rules/PHPUnit/CoversHelper.php +++ b/src/Rules/PHPUnit/CoversHelper.php @@ -105,11 +105,17 @@ public function processCovers( return $errors; } - $errors[] = RuleErrorBuilder::message(sprintf( + $error = RuleErrorBuilder::message(sprintf( '@covers value %s references an invalid %s.', $fullName, $isMethod ? 'method' : 'class or function' - ))->build(); + )); + + if (strpos($className, '\\') === false) { + $error->tip('The @covers annotation requires a fully qualified name.'); + } + + $errors[] = $error->build(); } return $errors; } diff --git a/tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php b/tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php index 7b84b50..32806ed 100644 --- a/tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php +++ b/tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php @@ -40,6 +40,11 @@ public function testRule(): void '@covers value does not specify anything.', 43, ], + [ + '@covers value NotFullyQualified references an invalid class or function.', + 50, + 'The @covers annotation requires a fully qualified name.', + ], ]); } diff --git a/tests/Rules/PHPUnit/data/class-coverage.php b/tests/Rules/PHPUnit/data/class-coverage.php index a5ddd18..35af204 100644 --- a/tests/Rules/PHPUnit/data/class-coverage.php +++ b/tests/Rules/PHPUnit/data/class-coverage.php @@ -43,3 +43,10 @@ function testable(): void class CoversNothing extends \PHPUnit\Framework\TestCase { } + +/** + * @covers NotFullyQualified + */ +class CoversNotFullyQualified extends \PHPUnit\Framework\TestCase +{ +}