Skip to content

Commit

Permalink
Do not create CodeCoverage object when --dump-xdebug-filter is used
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 15, 2019
1 parent 1a5c898 commit 978f824
Showing 1 changed file with 55 additions and 51 deletions.
106 changes: 55 additions & 51 deletions src/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,39 +478,6 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}

if ($codeCoverageReports > 0 || isset($arguments['xdebugFilterFile'])) {
$codeCoverage = new CodeCoverage(
null,
$this->codeCoverageFilter
);

$codeCoverage->setUnintentionallyCoveredSubclassesWhitelist(
[Comparator::class]
);

$codeCoverage->setCheckForUnintentionallyCoveredCode(
$arguments['strictCoverage']
);

$codeCoverage->setCheckForMissingCoversAnnotation(
$arguments['strictCoverage']
);

if (isset($arguments['forceCoversAnnotation'])) {
$codeCoverage->setForceCoversAnnotation(
$arguments['forceCoversAnnotation']
);
}

if (isset($arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage'])) {
$codeCoverage->setIgnoreDeprecatedCode(
$arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage']
);
}

if (isset($arguments['disableCodeCoverageIgnore'])) {
$codeCoverage->setDisableIgnoredLines(true);
}

$whitelistFromConfigurationFile = false;
$whitelistFromOption = false;

Expand All @@ -528,14 +495,6 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}

if (!empty($filterConfiguration['whitelist'])) {
$codeCoverage->setAddUncoveredFilesFromWhitelist(
$filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']
);

$codeCoverage->setProcessUncoveredFilesFromWhitelist(
$filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist']
);

foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
$this->codeCoverageFilter->addDirectoryToWhitelist(
$dir['path'],
Expand All @@ -561,23 +520,50 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}
}
}
}

if (isset($arguments['xdebugFilterFile'], $filterConfiguration)) {
$this->write("\n");
if ($codeCoverageReports > 0) {
$codeCoverage = new CodeCoverage(
null,
$this->codeCoverageFilter
);

$script = (new XdebugFilterScriptGenerator)->generate($filterConfiguration['whitelist']);
$codeCoverage->setUnintentionallyCoveredSubclassesWhitelist(
[Comparator::class]
);

if (!Filesystem::createDirectory(\dirname($arguments['xdebugFilterFile']))) {
$this->write(\sprintf('Cannot write Xdebug filter script to %s ' . \PHP_EOL, $arguments['xdebugFilterFile']));
$codeCoverage->setCheckForUnintentionallyCoveredCode(
$arguments['strictCoverage']
);

exit(self::EXCEPTION_EXIT);
}
$codeCoverage->setCheckForMissingCoversAnnotation(
$arguments['strictCoverage']
);

if (isset($arguments['forceCoversAnnotation'])) {
$codeCoverage->setForceCoversAnnotation(
$arguments['forceCoversAnnotation']
);
}

if (isset($arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage'])) {
$codeCoverage->setIgnoreDeprecatedCode(
$arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage']
);
}

\file_put_contents($arguments['xdebugFilterFile'], $script);
if (isset($arguments['disableCodeCoverageIgnore'])) {
$codeCoverage->setDisableIgnoredLines(true);
}

$this->write(\sprintf('Wrote Xdebug filter script to %s ' . \PHP_EOL, $arguments['xdebugFilterFile']));
if (!empty($filterConfiguration['whitelist'])) {
$codeCoverage->setAddUncoveredFilesFromWhitelist(
$filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']
);

exit(self::SUCCESS_EXIT);
$codeCoverage->setProcessUncoveredFilesFromWhitelist(
$filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist']
);
}

if (!$this->codeCoverageFilter->hasWhitelist()) {
Expand All @@ -593,6 +579,24 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}
}

if (isset($arguments['xdebugFilterFile'], $filterConfiguration)) {
$this->write("\n");

$script = (new XdebugFilterScriptGenerator)->generate($filterConfiguration['whitelist']);

if (!Filesystem::createDirectory(\dirname($arguments['xdebugFilterFile']))) {
$this->write(\sprintf('Cannot write Xdebug filter script to %s ' . \PHP_EOL, $arguments['xdebugFilterFile']));

exit(self::EXCEPTION_EXIT);
}

\file_put_contents($arguments['xdebugFilterFile'], $script);

$this->write(\sprintf('Wrote Xdebug filter script to %s ' . \PHP_EOL, $arguments['xdebugFilterFile']));

exit(self::SUCCESS_EXIT);
}

$this->printer->write("\n");

if (isset($codeCoverage)) {
Expand Down

0 comments on commit 978f824

Please sign in to comment.