diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 61b527411..652148b0b 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -56,6 +56,11 @@ final class CodeCoverage */ private $forceCoversAnnotation = false; + /** + * @var bool + */ + private $ignoreCoversAnnotation = false; + /** * @var bool */ @@ -417,6 +422,11 @@ public function setForceCoversAnnotation(bool $flag): void $this->forceCoversAnnotation = $flag; } + public function setIgnoreCoversAnnotation(bool $flag): void + { + $this->ignoreCoversAnnotation = $flag; + } + public function setCheckForMissingCoversAnnotation(bool $flag): void { $this->checkForMissingCoversAnnotation = $flag; @@ -464,6 +474,10 @@ public function setUnintentionallyCoveredSubclassesWhitelist(array $whitelist): */ private function applyCoversAnnotationFilter(array &$data, $linesToBeCovered, array $linesToBeUsed, bool $ignoreForceCoversAnnotation): void { + if ($this->ignoreCoversAnnotation) { + return; + } + if ($linesToBeCovered === false || ($this->forceCoversAnnotation && empty($linesToBeCovered) && !$ignoreForceCoversAnnotation)) { if ($this->checkForMissingCoversAnnotation) { diff --git a/tests/tests/CodeCoverageTest.php b/tests/tests/CodeCoverageTest.php index 091b78bc1..076fe3fde 100644 --- a/tests/tests/CodeCoverageTest.php +++ b/tests/tests/CodeCoverageTest.php @@ -157,6 +157,17 @@ public function testSetForceCoversAnnotation() ); } + public function testIgnoreCoversAnnotation() + { + $this->coverage->setIgnoreCoversAnnotation(true); + + $this->assertAttributeEquals( + true, + 'ignoreCoversAnnotation', + $this->coverage + ); + } + public function testSetCheckForUnexecutedCoveredCode() { $this->coverage->setCheckForUnexecutedCoveredCode(true);