Skip to content

[Postponed] Add option to ignore covers annotation #5274

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
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
4 changes: 4 additions & 0 deletions src/Runner/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public function init(Configuration $configuration, CodeCoverageFilterRegistry $c
$this->codeCoverage()->enableCheckForUnintentionallyCoveredCode();
}

if ($configuration->ignoreCoversAnnotation()) {
$this->codeCoverage()->ignoreCoversAnnotation();
}

if ($configuration->ignoreDeprecatedCodeUnitsFromCodeCoverage()) {
$this->codeCoverage()->ignoreDeprecatedCode();
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/TextUI/Configuration/Cli/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ final class Builder
'fail-on-skipped',
'fail-on-warning',
'strict-coverage',
'ignore-covers-annotation',
'disable-coverage-ignore',
'strict-global-state',
'teamcity',
Expand Down Expand Up @@ -206,6 +207,7 @@ public function fromParameters(array $parameters): Configuration
$reverseList = null;
$stderr = null;
$strictCoverage = null;
$ignoreCoversAnnotation = null;
$stopOnDefect = null;
$stopOnError = null;
$stopOnFailure = null;
Expand Down Expand Up @@ -649,6 +651,11 @@ public function fromParameters(array $parameters): Configuration

break;

case '--ignore-covers-annotation':
$ignoreCoversAnnotation = true;

break;

case '--disable-coverage-ignore':
$disableCodeCoverageIgnore = true;

Expand Down Expand Up @@ -833,6 +840,7 @@ public function fromParameters(array $parameters): Configuration
$reverseList,
$stderr,
$strictCoverage,
$ignoreCoversAnnotation,
$stopOnDefect,
$stopOnError,
$stopOnFailure,
Expand Down
24 changes: 23 additions & 1 deletion src/TextUI/Configuration/Cli/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ final class Configuration
private readonly ?bool $reverseList;
private readonly ?bool $stderr;
private readonly ?bool $strictCoverage;
private readonly ?bool $ignoreCoversAnnotation;
private readonly ?bool $stopOnDefect;
private readonly ?bool $stopOnError;
private readonly ?bool $stopOnFailure;
Expand Down Expand Up @@ -114,7 +115,7 @@ final class Configuration
/**
* @psalm-param ?non-empty-list<string> $testSuffixes
*/
public function __construct(?string $argument, ?string $atLeastVersion, ?bool $backupGlobals, ?bool $backupStaticProperties, ?bool $beStrictAboutChangesToGlobalState, ?string $bootstrap, ?string $cacheDirectory, ?bool $cacheResult, ?string $cacheResultFile, bool $checkVersion, ?string $colors, null|int|string $columns, ?string $configurationFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4J, ?string $coverageHtml, ?string $coveragePhp, ?string $coverageText, ?bool $coverageTextShowUncoveredFiles, ?bool $coverageTextShowOnlySummary, ?string $coverageXml, ?bool $pathCoverage, ?string $coverageCacheDirectory, bool $warmCoverageCache, ?int $defaultTimeLimit, ?bool $disableCodeCoverageIgnore, ?bool $disallowTestOutput, ?bool $enforceTimeLimit, ?array $excludeGroups, ?int $executionOrder, ?int $executionOrderDefects, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?string $filter, bool $generateConfiguration, bool $migrateConfiguration, ?array $groups, ?array $testsCovering, ?array $testsUsing, bool $help, ?string $includePath, ?array $iniSettings, ?string $junitLogfile, bool $listGroups, bool $listSuites, bool $listTests, ?string $listTestsXml, ?bool $noCoverage, ?bool $noExtensions, ?bool $noOutput, ?bool $noProgress, ?bool $noResults, ?bool $noLogging, ?bool $processIsolation, ?int $randomOrderSeed, ?bool $reportUselessTests, ?bool $resolveDependencies, ?bool $reverseList, ?bool $stderr, ?bool $strictCoverage, ?bool $stopOnDefect, ?bool $stopOnError, ?bool $stopOnFailure, ?bool $stopOnIncomplete, ?bool $stopOnRisky, ?bool $stopOnSkipped, ?bool $stopOnWarning, ?string $teamcityLogfile, ?string $testdoxHtmlFile, ?string $testdoxTextFile, ?array $testSuffixes, ?string $testSuite, ?string $excludeTestSuite, bool $useDefaultConfiguration, ?bool $displayDetailsOnIncompleteTests, ?bool $displayDetailsOnSkippedTests, ?bool $displayDetailsOnTestsThatTriggerDeprecations, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $printerTestDox)
public function __construct(?string $argument, ?string $atLeastVersion, ?bool $backupGlobals, ?bool $backupStaticProperties, ?bool $beStrictAboutChangesToGlobalState, ?string $bootstrap, ?string $cacheDirectory, ?bool $cacheResult, ?string $cacheResultFile, bool $checkVersion, ?string $colors, null|int|string $columns, ?string $configurationFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4J, ?string $coverageHtml, ?string $coveragePhp, ?string $coverageText, ?bool $coverageTextShowUncoveredFiles, ?bool $coverageTextShowOnlySummary, ?string $coverageXml, ?bool $pathCoverage, ?string $coverageCacheDirectory, bool $warmCoverageCache, ?int $defaultTimeLimit, ?bool $disableCodeCoverageIgnore, ?bool $disallowTestOutput, ?bool $enforceTimeLimit, ?array $excludeGroups, ?int $executionOrder, ?int $executionOrderDefects, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?string $filter, bool $generateConfiguration, bool $migrateConfiguration, ?array $groups, ?array $testsCovering, ?array $testsUsing, bool $help, ?string $includePath, ?array $iniSettings, ?string $junitLogfile, bool $listGroups, bool $listSuites, bool $listTests, ?string $listTestsXml, ?bool $noCoverage, ?bool $noExtensions, ?bool $noOutput, ?bool $noProgress, ?bool $noResults, ?bool $noLogging, ?bool $processIsolation, ?int $randomOrderSeed, ?bool $reportUselessTests, ?bool $resolveDependencies, ?bool $reverseList, ?bool $stderr, ?bool $strictCoverage, ?bool $ignoreCoversAnnotation, ?bool $stopOnDefect, ?bool $stopOnError, ?bool $stopOnFailure, ?bool $stopOnIncomplete, ?bool $stopOnRisky, ?bool $stopOnSkipped, ?bool $stopOnWarning, ?string $teamcityLogfile, ?string $testdoxHtmlFile, ?string $testdoxTextFile, ?array $testSuffixes, ?string $testSuite, ?string $excludeTestSuite, bool $useDefaultConfiguration, ?bool $displayDetailsOnIncompleteTests, ?bool $displayDetailsOnSkippedTests, ?bool $displayDetailsOnTestsThatTriggerDeprecations, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $printerTestDox)
{
$this->argument = $argument;
$this->atLeastVersion = $atLeastVersion;
Expand Down Expand Up @@ -181,6 +182,7 @@ public function __construct(?string $argument, ?string $atLeastVersion, ?bool $b
$this->reverseList = $reverseList;
$this->stderr = $stderr;
$this->strictCoverage = $strictCoverage;
$this->ignoreCoversAnnotation = $ignoreCoversAnnotation;
$this->stopOnDefect = $stopOnDefect;
$this->stopOnError = $stopOnError;
$this->stopOnFailure = $stopOnFailure;
Expand Down Expand Up @@ -1376,6 +1378,14 @@ public function hasStrictCoverage(): bool
return $this->strictCoverage !== null;
}

/**
* @psalm-assert-if-true !null $this->ignoreCoversAnnotation
*/
public function hasIgnoreCoversAnnotation(): bool
{
return $this->ignoreCoversAnnotation !== null;
}

/**
* @throws Exception
*/
Expand All @@ -1388,6 +1398,18 @@ public function strictCoverage(): bool
return $this->strictCoverage;
}

/**
* @throws Exception
*/
public function ignoreCoversAnnotation(): bool
{
if (!$this->hasIgnoreCoversAnnotation()) {
throw new Exception;
}

return $this->ignoreCoversAnnotation;
}

/**
* @psalm-assert-if-true !null $this->stopOnDefect
*/
Expand Down
9 changes: 8 additions & 1 deletion src/TextUI/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ final class Configuration
private readonly int $timeoutForLargeTests;
private readonly bool $reportUselessTests;
private readonly bool $strictCoverage;
private readonly bool $ignoreCoversAnnotation;
private readonly bool $disallowTestOutput;
private readonly bool $displayDetailsOnIncompleteTests;
private readonly bool $displayDetailsOnSkippedTests;
Expand Down Expand Up @@ -134,7 +135,7 @@ final class Configuration
* @psalm-param non-empty-list<string> $testSuffixes
* @psalm-param list<array{className: class-string, parameters: array<string, string>}> $extensionBootstrappers
*/
public function __construct(?string $cliArgument, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, FilterDirectoryCollection $coverageIncludeDirectories, FileCollection $coverageIncludeFiles, FilterDirectoryCollection $coverageExcludeDirectories, FileCollection $coverageExcludeFiles, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $stopOnDefect, bool $stopOnError, bool $stopOnFailure, bool $stopOnWarning, bool $stopOnIncomplete, bool $stopOnRisky, bool $stopOnSkipped, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $registerMockObjectsFromTestArgumentsRecursively, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?array $groups, ?array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php)
public function __construct(?string $cliArgument, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, FilterDirectoryCollection $coverageIncludeDirectories, FileCollection $coverageIncludeFiles, FilterDirectoryCollection $coverageExcludeDirectories, FileCollection $coverageExcludeFiles, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $stopOnDefect, bool $stopOnError, bool $stopOnFailure, bool $stopOnWarning, bool $stopOnIncomplete, bool $stopOnRisky, bool $stopOnSkipped, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $ignoreCoversAnnotation, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $registerMockObjectsFromTestArgumentsRecursively, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?array $groups, ?array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php)
{
$this->cliArgument = $cliArgument;
$this->configurationFile = $configurationFile;
Expand Down Expand Up @@ -197,6 +198,7 @@ public function __construct(?string $cliArgument, ?string $configurationFile, ?s
$this->timeoutForLargeTests = $timeoutForLargeTests;
$this->reportUselessTests = $reportUselessTests;
$this->strictCoverage = $strictCoverage;
$this->ignoreCoversAnnotation = $ignoreCoversAnnotation;
$this->disallowTestOutput = $disallowTestOutput;
$this->displayDetailsOnIncompleteTests = $displayDetailsOnIncompleteTests;
$this->displayDetailsOnSkippedTests = $displayDetailsOnSkippedTests;
Expand Down Expand Up @@ -778,6 +780,11 @@ public function strictCoverage(): bool
return $this->strictCoverage;
}

public function ignoreCoversAnnotation(): bool
{
return $this->ignoreCoversAnnotation;
}

public function disallowTestOutput(): bool
{
return $this->disallowTestOutput;
Expand Down
7 changes: 7 additions & 0 deletions src/TextUI/Configuration/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$strictCoverage = $xmlConfiguration->phpunit()->beStrictAboutCoverageMetadata();
}

if ($cliConfiguration->hasIgnoreCoversAnnotation()) {
$ignoreCoversAnnotation = $cliConfiguration->ignoreCoversAnnotation();
} else {
$ignoreCoversAnnotation = $xmlConfiguration->phpunit()->beIgnoreCoversAnnotation();
}

if ($cliConfiguration->hasDisallowTestOutput()) {
$disallowTestOutput = $cliConfiguration->disallowTestOutput();
} else {
Expand Down Expand Up @@ -735,6 +741,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$timeoutForLargeTests,
$reportUselessTests,
$strictCoverage,
$ignoreCoversAnnotation,
$disallowTestOutput,
$displayDetailsOnIncompleteTests,
$displayDetailsOnSkippedTests,
Expand Down
1 change: 1 addition & 0 deletions src/TextUI/Configuration/Xml/DefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static function create(): self
true,
false,
false,
false,
1,
1,
10,
Expand Down
1 change: 1 addition & 0 deletions src/TextUI/Configuration/Xml/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ private function phpunit(string $filename, DOMDocument $document): PHPUnit
$this->getBooleanAttribute($document->documentElement, 'beStrictAboutOutputDuringTests', false),
$this->getBooleanAttribute($document->documentElement, 'beStrictAboutTestsThatDoNotTestAnything', true),
$beStrictAboutCoverageMetadata,
$this->getBooleanAttribute($document->documentElement, 'beIgnoreCoversAttribute', false),
$this->getBooleanAttribute($document->documentElement, 'enforceTimeLimit', false),
$this->getIntegerAttribute($document->documentElement, 'defaultTimeLimit', 1),
$this->getIntegerAttribute($document->documentElement, 'timeoutForSmallTests', 1),
Expand Down
Loading