Skip to content

Commit 34ee324

Browse files
mad-brillerondrejmirtes
authored andcommitted
Fixed false positive when covering a global function.
1 parent 4a19a3c commit 34ee324

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/Rules/PHPUnit/CoversHelper.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ public function processCovers(
7171
{
7272
$errors = [];
7373
$covers = (string) $phpDocTag->value;
74+
75+
if ($covers === '') {
76+
$errors[] = RuleErrorBuilder::message('@covers value does not specify anything.')->build();
77+
78+
return $errors;
79+
}
80+
7481
$isMethod = strpos($covers, '::') !== false;
7582
$fullName = $covers;
7683

@@ -94,17 +101,12 @@ public function processCovers(
94101
$fullName
95102
))->build();
96103
}
97-
} else {
98-
if ($covers === '') {
99-
$errors[] = RuleErrorBuilder::message('@covers value does not specify anything.')->build();
100-
101-
return $errors;
102-
}
103-
104-
if (!isset($method) && $this->reflectionProvider->hasFunction(new Name($covers, []), null)) {
105-
return $errors;
106-
}
104+
} elseif (isset($method) && $this->reflectionProvider->hasFunction(new Name($method, []), null)) {
105+
return $errors;
106+
} elseif (!isset($method) && $this->reflectionProvider->hasFunction(new Name($className, []), null)) {
107+
return $errors;
107108

109+
} else {
108110
$error = RuleErrorBuilder::message(sprintf(
109111
'@covers value %s references an invalid %s.',
110112
$fullName,

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

+7
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ class CoversNothing extends \PHPUnit\Framework\TestCase
5050
class CoversNotFullyQualified extends \PHPUnit\Framework\TestCase
5151
{
5252
}
53+
54+
/**
55+
* @covers ::str_replace
56+
*/
57+
class CoversGlobalFunction extends \PHPUnit\Framework\TestCase
58+
{
59+
}

0 commit comments

Comments
 (0)