Skip to content

Commit

Permalink
Merge pull request #3 from vemaeg/feature/support-for-cobertura
Browse files Browse the repository at this point in the history
Added support for cobertura file format.
  • Loading branch information
thirsch authored Sep 11, 2021
2 parents 54aa493 + 9d3eef2 commit 0ffd4bb
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/PhpunitMerger/Command/CoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Filter as CodeCoverageFilter;
use SebastianBergmann\CodeCoverage\Report\Clover;
use SebastianBergmann\CodeCoverage\Report\Cobertura;
use SebastianBergmann\CodeCoverage\Report\Html\Facade;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -49,6 +50,12 @@ protected function configure()
null,
InputOption::VALUE_REQUIRED,
'The highLowerBound value to be used for HTML format'
)
->addOption(
'cobertura',
null,
InputOption::VALUE_NONE,
'Export cobertura instead of clover'
);
}

Expand All @@ -68,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$codeCoverage->merge($coverage);
}

$this->writeCodeCoverage($codeCoverage, $output, $input->getArgument('file'));
$this->writeCodeCoverage($codeCoverage, $output, $input->getArgument('file'), $input->getOption('cobertura') ?? false);
$html = $input->getOption('html');
if ($html !== null) {
$lowUpperBound = (int)($input->getOption('lowUpperBound') ?: 50);
Expand All @@ -91,9 +98,18 @@ private function getCodeCoverage()
return new CodeCoverage($driver, $filter);
}

private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $output, $file = null)
private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $output, $file = null, bool $cobertura = false)
{
$writer = new Clover();
if ($cobertura) {
if (!class_exists(Cobertura::class)) {
$output->writeln('Cobertura writer not found. Are you using a too old phpunit version? You need at least version 9.4.');
exit(1);
}
$writer = new Cobertura();
} else {
$writer = new Clover();
}

$buffer = $writer->process($codeCoverage, $file);
if ($file === null) {
$output->write($buffer);
Expand Down

0 comments on commit 0ffd4bb

Please sign in to comment.