Skip to content

Commit

Permalink
Don't show any warning messages about missing coverage driver when `-…
Browse files Browse the repository at this point in the history
…-no-coverage` CLI option is used. Fixes #28
  • Loading branch information
dvdoug committed Nov 16, 2024
1 parent b2dfc18 commit c252c72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased] - 2024-xx-xx

## [5.3.6] - 2024-11-16
### Fixed
- Don't show any warning messages about missing coverage driver when `--no-coverage` CLI option is used

## [5.3.5] - 2024-09-22
### Changed
- Use `stderr` instead of `stdout` for warnings
Expand Down Expand Up @@ -126,8 +130,9 @@
- Support for Symfony components older than `<3.4`
- Support for HHVM

[Unreleased]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.5..master
[Unreleased]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.6..master

[5.3.6]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.5..v5.3.6
[5.3.5]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.4..v5.3.5
[5.3.4]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.3..v5.3.4
[5.3.3]: https://github.com/dvdoug/behat-code-coverage/compare/v5.3.2.1..v5.3.3
Expand Down
24 changes: 13 additions & 11 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,22 @@ public function process(ContainerBuilder $container): void
$branchPathConfig = $container->getParameter('behat.code_coverage.config.branchAndPathCoverage');
$cacheDir = $container->getParameter('behat.code_coverage.config.cache');

$canCollectCodeCoverage = true;
try {
$this->initCodeCoverage(new Filter(), $filterConfig, $branchPathConfig, $cacheDir, $output);
$canCollectCodeCoverage = !$input->hasParameterOption('--no-coverage');
if ($canCollectCodeCoverage) {
try {
$this->initCodeCoverage(new Filter(), $filterConfig, $branchPathConfig, $cacheDir, $output);

$codeCoverageDefinition = $container->getDefinition(CodeCoverage::class);
$filterDefinition = $container->getDefinition(Filter::class);
$codeCoverageDefinition->setFactory([new Reference(self::class), 'initCodeCoverage']);
$codeCoverageDefinition->setArguments([$filterDefinition, $filterConfig, $branchPathConfig, $cacheDir, $output]);
} catch (NoCodeCoverageDriverAvailableException|XdebugNotEnabledException|XdebugNotAvailableException $e) {
$output->writeln("<comment>No code coverage driver is available. {$e->getMessage()}</comment>");
$canCollectCodeCoverage = false;
$codeCoverageDefinition = $container->getDefinition(CodeCoverage::class);
$filterDefinition = $container->getDefinition(Filter::class);
$codeCoverageDefinition->setFactory([new Reference(self::class), 'initCodeCoverage']);
$codeCoverageDefinition->setArguments([$filterDefinition, $filterConfig, $branchPathConfig, $cacheDir, $output]);
} catch (NoCodeCoverageDriverAvailableException|XdebugNotEnabledException|XdebugNotAvailableException $e) {
$output->writeln("<comment>{$e->getMessage()}</comment>");
$canCollectCodeCoverage = false;
}
}

if (!$canCollectCodeCoverage || $input->hasParameterOption('--no-coverage')) {
if (!$canCollectCodeCoverage) {
$container->getDefinition(EventSubscriber::class)->setArgument('$coverage', null);
}
}
Expand Down

0 comments on commit c252c72

Please sign in to comment.