Skip to content

Commit 5cffc27

Browse files
authored
Merge pull request #15 from i6systems/add-bounds-options
2 parents 632e061 + f42f8cc commit 5cffc27

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ $ vendor/bin/phpunit-merger coverage <directory> [--html=<directory>] [<file>]
3737
**Options**
3838

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

4143
### Log
4244

src/PhpunitMerger/Command/CoverageCommand.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ protected function configure()
3737
null,
3838
InputOption::VALUE_REQUIRED,
3939
'The directory where to write the code coverage report in HTML format'
40+
)
41+
->addOption(
42+
'lowUpperBound',
43+
null,
44+
InputOption::VALUE_REQUIRED,
45+
'The lowUpperBound value to be used for HTML format'
46+
)
47+
->addOption(
48+
'highLowerBound',
49+
null,
50+
InputOption::VALUE_REQUIRED,
51+
'The highLowerBound value to be used for HTML format'
4052
);
4153
}
4254

@@ -59,7 +71,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
5971
$this->writeCodeCoverage($codeCoverage, $output, $input->getArgument('file'));
6072
$html = $input->getOption('html');
6173
if ($html !== null) {
62-
$this->writeHtmlReport($codeCoverage, $html);
74+
$lowUpperBound = (int)($input->getOption('lowUpperBound') ?: 50);
75+
$highLowerBound = (int)($input->getOption('highLowerBound') ?: 90);
76+
$this->writeHtmlReport($codeCoverage, $html, $lowUpperBound, $highLowerBound);
6377
}
6478

6579
return 0;
@@ -86,9 +100,9 @@ private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $
86100
}
87101
}
88102

89-
private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination)
103+
private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination, int $lowUpperBound, int $highLowerBound)
90104
{
91-
$writer = new Facade();
105+
$writer = new Facade($lowUpperBound, $highLowerBound);
92106
$writer->process($codeCoverage, $destination);
93107
}
94108
}

tests/PhpunitMerger/Command/Coverage/CoverageCommandTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,39 @@ public function testCoverageWritesHtmlReport()
7575
$this->assertFileExists($this->logDirectory . $this->outputFile);
7676
}
7777

78+
public function testCoverageWritesHtmlReportWithCustomBounds()
79+
{
80+
$this->outputFile = 'html/index.html';
81+
$this->assertOutputDirectoryNotExists();
82+
83+
$input = new ArgvInput(
84+
[
85+
'coverage',
86+
$this->logDirectory . 'coverage/',
87+
'--html=' . $this->logDirectory . dirname($this->outputFile),
88+
'--lowUpperBound=20',
89+
'--highLowerBound=70',
90+
]
91+
);
92+
$output = $this->prophesize(OutputInterface::class);
93+
$output->write(Argument::type('string'))->shouldBeCalled();
94+
95+
$command = new CoverageCommand();
96+
$command->run($input, $output->reveal());
97+
98+
$this->assertFileExists($this->logDirectory . $this->outputFile);
99+
100+
$content = file_get_contents($this->logDirectory . $this->outputFile);
101+
if (method_exists($this, 'assertStringContainsString')) {
102+
$this->assertStringContainsString('<strong>Low</strong>: 0% to 20%', $content);
103+
$this->assertStringContainsString('<strong>High</strong>: 70% to 100%', $content);
104+
} else {
105+
// Fallback for phpunit < 7.0
106+
$this->assertContains('<strong>Low</strong>: 0% to 20%', $content);
107+
$this->assertContains('<strong>High</strong>: 70% to 100%', $content);
108+
}
109+
}
110+
78111
public function testCoverageWritesOutputFileAndHtmlReport()
79112
{
80113
$this->outputFile = 'html/coverage.xml';

0 commit comments

Comments
 (0)