Skip to content

Commit

Permalink
Add interface to specify custom.css file for HTML report
Browse files Browse the repository at this point in the history
Related to sebastianbergmann#556.

It would help to make the custom CSS feature more accessible by making
the file a configuration option, e.g. in phpunit:

    <coverage>
        <report>
            <html customCssFile="path/to/custom.css" />
        </report>
    </coverage>

The `$customCssFile` argument is added to the Html\Facade interface as
a prerequisite to any changes to phpunit configuration options. If not
null, it copies this file to the custom.css destination instead of the
empty custom.css stub file.
  • Loading branch information
hemberger committed Feb 21, 2022
1 parent 75a0f91 commit 4ebadcd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Report/Html/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ final class Facade
*/
private $highLowerBound;

public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, string $generator = '')
/**
* @var ?string
*/
private $customCssFile;

public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, string $generator = '', ?string $customCssFile = null)
{
if ($lowUpperBound > $highLowerBound) {
throw new InvalidArgumentException(
Expand All @@ -52,6 +57,7 @@ public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, s
$this->generator = $generator;
$this->highLowerBound = $highLowerBound;
$this->lowUpperBound = $lowUpperBound;
$this->customCssFile = $customCssFile;
$this->templatePath = __DIR__ . '/Renderer/Template/';
}

Expand Down Expand Up @@ -118,7 +124,7 @@ 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->customCssFile ?? $this->templatePath . 'css/custom.css', $dir . 'custom.css');
copy($this->templatePath . 'css/octicons.css', $dir . 'octicons.css');

$dir = $this->directory($target . '_icons');
Expand Down

0 comments on commit 4ebadcd

Please sign in to comment.