Skip to content

Commit

Permalink
Make code coverage colors configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 22, 2022
1 parent b7559cf commit 1f6a9a5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
45 changes: 39 additions & 6 deletions src/Report/Html/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use SebastianBergmann\CodeCoverage\Directory as DirectoryUtil;
use SebastianBergmann\CodeCoverage\InvalidArgumentException;
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
use SebastianBergmann\Template\Template;

final class Facade
{
Expand All @@ -29,18 +30,33 @@ final class Facade

private int $highLowerBound;

public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, string $generator = '')
private string $colorSuccessLow;

private string $colorSuccessMedium;

private string $colorSuccessHigh;

private string $colorWarning;

private string $colorDanger;

public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, string $generator = '', string $colorSuccessLow = '#dff0d8', string $colorSuccessMedium = '#c3e3b5', string $colorSuccessHigh = '#99cb84', string $colorWarning = '#fcf8e3', string $colorDanger = '#f2dede')
{
if ($lowUpperBound > $highLowerBound) {
throw new InvalidArgumentException(
'$lowUpperBound must not be larger than $highLowerBound'
);
}

$this->generator = $generator;
$this->highLowerBound = $highLowerBound;
$this->lowUpperBound = $lowUpperBound;
$this->templatePath = __DIR__ . '/Renderer/Template/';
$this->generator = $generator;
$this->highLowerBound = $highLowerBound;
$this->lowUpperBound = $lowUpperBound;
$this->colorSuccessLow = $colorSuccessLow;
$this->colorSuccessMedium = $colorSuccessMedium;
$this->colorSuccessHigh = $colorSuccessHigh;
$this->colorWarning = $colorWarning;
$this->colorDanger = $colorDanger;
$this->templatePath = __DIR__ . '/Renderer/Template/';
}

public function process(CodeCoverage $coverage, string $target): void
Expand Down Expand Up @@ -97,6 +113,7 @@ public function process(CodeCoverage $coverage, string $target): void
}

$this->copyFiles($target);
$this->renderCss($target);
}

private function copyFiles(string $target): void
Expand All @@ -105,7 +122,6 @@ private function copyFiles(string $target): void

copy($this->templatePath . 'css/bootstrap.min.css', $dir . 'bootstrap.min.css');
copy($this->templatePath . 'css/nv.d3.min.css', $dir . 'nv.d3.min.css');
copy($this->templatePath . 'css/style.css', $dir . 'style.css');
copy($this->templatePath . 'css/custom.css', $dir . 'custom.css');
copy($this->templatePath . 'css/octicons.css', $dir . 'octicons.css');

Expand All @@ -122,6 +138,23 @@ private function copyFiles(string $target): void
copy($this->templatePath . 'js/file.js', $dir . 'file.js');
}

private function renderCss(string $target): void
{
$template = new Template($this->templatePath . 'css/style.css', '{{', '}}');

$template->setVar(
[
'success-low' => $this->colorSuccessLow,
'success-medium' => $this->colorSuccessMedium,
'success-high' => $this->colorSuccessHigh,
'warning' => $this->colorWarning,
'danger' => $this->colorDanger,
]
);

$template->renderTo($this->directory($target . '_css') . 'style.css');
}

private function directory(string $directory): string
{
if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) {
Expand Down
14 changes: 7 additions & 7 deletions src/Report/Html/Renderer/Template/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ body {
}

.table tbody tr.covered-by-large-tests, li.covered-by-large-tests, tr.success, td.success, li.success, span.success {
background-color: #dff0d8;
background-color: {{success-low}};
}

.table tbody tr.covered-by-medium-tests, li.covered-by-medium-tests {
background-color: #c3e3b5;
background-color: {{success-medium}};
}

.table tbody tr.covered-by-small-tests, li.covered-by-small-tests {
background-color: #99cb84;
background-color: {{success-high}};
}

.table tbody tr.danger, .table tbody td.danger, li.danger, span.danger {
background-color: #f2dede;
.table tbody tr.warning, .table tbody td.warning, li.warning, span.warning {
background-color: {{warning}};
}

.table tbody tr.warning, .table tbody td.warning, li.warning, span.warning {
background-color: #fcf8e3;
.table tbody tr.danger, .table tbody td.danger, li.danger, span.danger {
background-color: {{danger}};
}

.table tbody td.info {
Expand Down

0 comments on commit 1f6a9a5

Please sign in to comment.