Skip to content

Commit

Permalink
Be explicit with covers messaging when using @coversDefaultClass and @…
Browse files Browse the repository at this point in the history
  • Loading branch information
mad-briller authored and ondrejmirtes committed Oct 28, 2022
1 parent dc08630 commit dea1f87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Rules/PHPUnit/CoversHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function processCovers(
$errors = [];
$covers = (string) $phpDocTag->value;
$isMethod = strpos($covers, '::') !== false;
$fullName = $covers;

if ($isMethod) {
[$className, $method] = explode('::', $covers);
Expand All @@ -81,6 +82,7 @@ public function processCovers(

if ($className === '' && $node instanceof Node\Stmt\ClassMethod && $coversDefaultClass !== null) {
$className = (string) $coversDefaultClass->value;
$fullName = $className . $covers;
}

if ($this->reflectionProvider->hasClass($className)) {
Expand All @@ -89,7 +91,7 @@ public function processCovers(
if (isset($method) && $method !== '' && !$class->hasMethod($method)) {
$errors[] = RuleErrorBuilder::message(sprintf(
'@covers value %s references an invalid method.',
$covers
$fullName
))->build();
}
} else {
Expand All @@ -99,7 +101,7 @@ public function processCovers(

$errors[] = RuleErrorBuilder::message(sprintf(
'@covers value %s references an invalid %s.',
$covers,
$fullName,
$isMethod ? 'method' : 'class or function'
))->build();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/PHPUnit/ClassMethodCoversExistsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testRule(): void
{
$this->analyse([__DIR__ . '/data/method-coverage.php'], [
[
'@covers value ::ignoreThis references an invalid method.',
'@covers value \Not\A\Class::ignoreThis references an invalid method.',
14,
],
[
Expand All @@ -42,7 +42,7 @@ public function testRule(): void
50,
],
[
'@covers value ::assertNotReal references an invalid method.',
'@covers value \PHPUnit\Framework\TestCase::assertNotReal references an invalid method.',
62,
],
[
Expand Down

0 comments on commit dea1f87

Please sign in to comment.