Skip to content

Commit

Permalink
Adds options for lowUpperBound and highLowerBound for HTML reports
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos granados committed Oct 2, 2020
1 parent 632e061 commit bb52378
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ $ vendor/bin/phpunit-merger coverage <directory> [--html=<directory>] [<file>]
**Options**

- `html`: Directory where the HTML report should be stored
- `lowUpperBound`: (optional) The lowUpperBound value to be used for HTML format
- `highLowerBound`: (optional) The highLowerBound value to be used for HTML format

### Log

Expand Down
20 changes: 17 additions & 3 deletions src/PhpunitMerger/Command/CoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ protected function configure()
null,
InputOption::VALUE_REQUIRED,
'The directory where to write the code coverage report in HTML format'
)
->addOption(
'lowUpperBound',
null,
InputOption::VALUE_REQUIRED,
'The lowUpperBound value to be used for HTML format'
)
->addOption(
'highLowerBound',
null,
InputOption::VALUE_REQUIRED,
'The highLowerBound value to be used for HTML format'
);
}

Expand All @@ -59,7 +71,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->writeCodeCoverage($codeCoverage, $output, $input->getArgument('file'));
$html = $input->getOption('html');
if ($html !== null) {
$this->writeHtmlReport($codeCoverage, $html);
$lowUpperBound = $input->getOption('lowUpperBound') ?: 50;
$highLowerBound = $input->getOption('highLowerBound') ?: 90;
$this->writeHtmlReport($codeCoverage, $html, $lowUpperBound, $highLowerBound);
}

return 0;
Expand All @@ -86,9 +100,9 @@ private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $
}
}

private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination)
private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination, int $lowUpperBound, int $highLowerBound)
{
$writer = new Facade();
$writer = new Facade($lowUpperBound, $highLowerBound);
$writer->process($codeCoverage, $destination);
}
}
23 changes: 23 additions & 0 deletions tests/PhpunitMerger/Command/Coverage/CoverageCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ public function testCoverageWritesHtmlReport()
$this->assertFileExists($this->logDirectory . $this->outputFile);
}

public function testCoverageWritesHtmlReportWithCustomBounds()
{
$this->outputFile = 'html/index.html';
$this->assertOutputDirectoryNotExists();

$input = new ArgvInput(
[
'coverage',
$this->logDirectory . 'coverage/',
'--html=' . $this->logDirectory . dirname($this->outputFile),
'--lowUpperBound=20',
'--highLowerBound=70',
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::type('string'))->shouldBeCalled();

$command = new CoverageCommand();
$command->run($input, $output->reveal());

$this->assertFileExists($this->logDirectory . $this->outputFile);
}

public function testCoverageWritesOutputFileAndHtmlReport()
{
$this->outputFile = 'html/coverage.xml';
Expand Down

0 comments on commit bb52378

Please sign in to comment.