Skip to content

Commit

Permalink
Add tip to error when a not fully qualified name is seen in @Covers a…
Browse files Browse the repository at this point in the history
…nnotation.
  • Loading branch information
mad-briller authored and ondrejmirtes committed Feb 25, 2023
1 parent 7e43c8f commit 4a19a3c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Rules/PHPUnit/CoversHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
]);
}

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 @@ -43,3 +43,10 @@ function testable(): void
class CoversNothing extends \PHPUnit\Framework\TestCase
{
}

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

0 comments on commit 4a19a3c

Please sign in to comment.