diff --git a/src/Rules/PHPUnit/CoversHelper.php b/src/Rules/PHPUnit/CoversHelper.php index 792fcc1..66d6edf 100644 --- a/src/Rules/PHPUnit/CoversHelper.php +++ b/src/Rules/PHPUnit/CoversHelper.php @@ -71,6 +71,13 @@ public function processCovers( { $errors = []; $covers = (string) $phpDocTag->value; + + if ($covers === '') { + $errors[] = RuleErrorBuilder::message('@covers value does not specify anything.')->build(); + + return $errors; + } + $isMethod = strpos($covers, '::') !== false; $fullName = $covers; @@ -94,17 +101,12 @@ public function processCovers( $fullName ))->build(); } - } else { - if ($covers === '') { - $errors[] = RuleErrorBuilder::message('@covers value does not specify anything.')->build(); - - return $errors; - } - - if (!isset($method) && $this->reflectionProvider->hasFunction(new Name($covers, []), null)) { - return $errors; - } + } elseif (isset($method) && $this->reflectionProvider->hasFunction(new Name($method, []), null)) { + return $errors; + } elseif (!isset($method) && $this->reflectionProvider->hasFunction(new Name($className, []), null)) { + return $errors; + } else { $error = RuleErrorBuilder::message(sprintf( '@covers value %s references an invalid %s.', $fullName, diff --git a/tests/Rules/PHPUnit/data/class-coverage.php b/tests/Rules/PHPUnit/data/class-coverage.php index 35af204..2d4e0ef 100644 --- a/tests/Rules/PHPUnit/data/class-coverage.php +++ b/tests/Rules/PHPUnit/data/class-coverage.php @@ -50,3 +50,10 @@ class CoversNothing extends \PHPUnit\Framework\TestCase class CoversNotFullyQualified extends \PHPUnit\Framework\TestCase { } + +/** + * @covers ::str_replace + */ +class CoversGlobalFunction extends \PHPUnit\Framework\TestCase +{ +}