Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4a19a3c

Browse files
mad-brillerondrejmirtes
authored andcommitted
Add tip to error when a not fully qualified name is seen in @Covers annotation.
1 parent 7e43c8f commit 4a19a3c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

‎src/Rules/PHPUnit/CoversHelper.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,17 @@ public function processCovers(
105105
return $errors;
106106
}
107107

108-
$errors[] = RuleErrorBuilder::message(sprintf(
108+
$error = RuleErrorBuilder::message(sprintf(
109109
'@covers value %s references an invalid %s.',
110110
$fullName,
111111
$isMethod ? 'method' : 'class or function'
112-
))->build();
112+
));
113+
114+
if (strpos($className, '\\') === false) {
115+
$error->tip('The @covers annotation requires a fully qualified name.');
116+
}
117+
118+
$errors[] = $error->build();
113119
}
114120
return $errors;
115121
}

‎tests/Rules/PHPUnit/ClassCoversExistsRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function testRule(): void
4040
'@covers value does not specify anything.',
4141
43,
4242
],
43+
[
44+
'@covers value NotFullyQualified references an invalid class or function.',
45+
50,
46+
'The @covers annotation requires a fully qualified name.',
47+
],
4348
]);
4449
}
4550

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ function testable(): void
4343
class CoversNothing extends \PHPUnit\Framework\TestCase
4444
{
4545
}
46+
47+
/**
48+
* @covers NotFullyQualified
49+
*/
50+
class CoversNotFullyQualified extends \PHPUnit\Framework\TestCase
51+
{
52+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /