Skip to content

Commit dea1f87

Browse files
mad-brillerondrejmirtes
authored andcommitted
Be explicit with covers messaging when using @coversDefaultClass and @Covers.
1 parent dc08630 commit dea1f87

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Rules/PHPUnit/CoversHelper.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function processCovers(
7272
$errors = [];
7373
$covers = (string) $phpDocTag->value;
7474
$isMethod = strpos($covers, '::') !== false;
75+
$fullName = $covers;
7576

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

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

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

100102
$errors[] = RuleErrorBuilder::message(sprintf(
101103
'@covers value %s references an invalid %s.',
102-
$covers,
104+
$fullName,
103105
$isMethod ? 'method' : 'class or function'
104106
))->build();
105107
}

tests/Rules/PHPUnit/ClassMethodCoversExistsRuleTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testRule(): void
2626
{
2727
$this->analyse([__DIR__ . '/data/method-coverage.php'], [
2828
[
29-
'@covers value ::ignoreThis references an invalid method.',
29+
'@covers value \Not\A\Class::ignoreThis references an invalid method.',
3030
14,
3131
],
3232
[
@@ -42,7 +42,7 @@ public function testRule(): void
4242
50,
4343
],
4444
[
45-
'@covers value ::assertNotReal references an invalid method.',
45+
'@covers value \PHPUnit\Framework\TestCase::assertNotReal references an invalid method.',
4646
62,
4747
],
4848
[

0 commit comments

Comments
 (0)