Skip to content

Add option to ignore covers annotation #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ final class CodeCoverage
*/
private $forceCoversAnnotation = false;

/**
* @var bool
*/
private $ignoreCoversAnnotation = false;

/**
* @var bool
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions tests/tests/CodeCoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down