From b939d94cda32b42a7b2125784adc824fcf874d0d Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 2 Mar 2023 22:56:09 +0000 Subject: [PATCH] fix: non needded output --- .../Command/WarmCodeCoverageCacheCommand.php | 103 ++++++++++++++++++ src/Bootstrappers/BootOverrides.php | 1 + 2 files changed, 104 insertions(+) create mode 100644 overrides/TextUI/Command/WarmCodeCoverageCacheCommand.php diff --git a/overrides/TextUI/Command/WarmCodeCoverageCacheCommand.php b/overrides/TextUI/Command/WarmCodeCoverageCacheCommand.php new file mode 100644 index 00000000..42348229 --- /dev/null +++ b/overrides/TextUI/Command/WarmCodeCoverageCacheCommand.php @@ -0,0 +1,103 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TextUI\Command; + +use function printf; +use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry; +use PHPUnit\TextUI\Configuration\Configuration; +use PHPUnit\TextUI\Configuration\NoCoverageCacheDirectoryException; +use SebastianBergmann\CodeCoverage\StaticAnalysis\CacheWarmer; +use SebastianBergmann\Timer\NoActiveTimerException; +use SebastianBergmann\Timer\Timer; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class WarmCodeCoverageCacheCommand implements Command +{ + private readonly Configuration $configuration; + private readonly CodeCoverageFilterRegistry $codeCoverageFilterRegistry; + + public function __construct(Configuration $configuration, CodeCoverageFilterRegistry $codeCoverageFilterRegistry) + { + $this->configuration = $configuration; + $this->codeCoverageFilterRegistry = $codeCoverageFilterRegistry; + } + + /** + * @throws NoActiveTimerException + * @throws NoCoverageCacheDirectoryException + */ + public function execute(): Result + { + if (!$this->configuration->hasCoverageCacheDirectory()) { + return Result::from( + 'Cache for static analysis has not been configured' . PHP_EOL, + Result::FAILURE + ); + } + + $this->codeCoverageFilterRegistry->init($this->configuration); + + if (!$this->codeCoverageFilterRegistry->configured()) { + return Result::from( + 'Filter for code coverage has not been configured' . PHP_EOL, + Result::FAILURE + ); + } + + $timer = new Timer; + $timer->start(); + + (new CacheWarmer)->warmCache( + $this->configuration->coverageCacheDirectory(), + !$this->configuration->disableCodeCoverageIgnore(), + $this->configuration->ignoreDeprecatedCodeUnitsFromCodeCoverage(), + $this->codeCoverageFilterRegistry->get() + ); + + return Result::from(); + } +} diff --git a/src/Bootstrappers/BootOverrides.php b/src/Bootstrappers/BootOverrides.php index 7b3d2307..d25f935d 100644 --- a/src/Bootstrappers/BootOverrides.php +++ b/src/Bootstrappers/BootOverrides.php @@ -21,6 +21,7 @@ final class BootOverrides implements Bootstrapper 'Runner/Filter/NameFilterIterator.php', 'Runner/ResultCache/DefaultResultCache.php', 'Runner/TestSuiteLoader.php', + 'TextUI/Command/WarmCodeCoverageCacheCommand.php', 'TextUI/Output/Default/ProgressPrinter/TestSkippedSubscriber.php', ];