Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Bootstrap 5 and adds theme support for code coverage. #1036

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
'generator' => $this->generator,
'low_upper_bound' => $this->thresholds->lowUpperBound(),
'high_lower_bound' => $this->thresholds->highLowerBound(),
'theme' => $this->theme,
]]]></code>
</InvalidArgument>
<PossiblyUndefinedArrayOffset>
Expand Down
22 changes: 18 additions & 4 deletions src/Report/Html/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ final class Colors
private readonly string $successHigh;
private readonly string $warning;
private readonly string $danger;
private readonly string $theme;

public static function default(): self
{
return new self('#dff0d8', '#c3e3b5', '#99cb84', '#fcf8e3', '#f2dede');
return new self(
'rgb(from var(--bs-success) r g b / 0.25)',
'rgb(from var(--bs-success) r g b / 0.5)',
'rgb(from var(--bs-success) r g b / 0.75)',
'rgb(from var(--bs-warning) r g b / 0.25)',
'rgb(from var(--bs-danger) r g b / 0.25)',
// 'dark', // or any other theme name defined in customCssFile
);
}

public static function from(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger): self
public static function from(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger, string $theme = ''): self
{
return new self($successLow, $successMedium, $successHigh, $warning, $danger);
return new self($successLow, $successMedium, $successHigh, $warning, $danger, $theme);
}

private function __construct(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger)
private function __construct(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger, string $theme = '')
{
$this->successLow = $successLow;
$this->successMedium = $successMedium;
$this->successHigh = $successHigh;
$this->warning = $warning;
$this->danger = $danger;
$this->theme = $theme;
}

public function successLow(): string
Expand All @@ -63,4 +72,9 @@ public function danger(): string
{
return $this->danger;
}

public function theme(): string
{
return $this->theme;
}
}
6 changes: 4 additions & 2 deletions src/Report/Html/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function process(CodeCoverage $coverage, string $target): void
$date,
$this->thresholds,
$coverage->collectsBranchAndPathCoverage(),
$this->colors->theme(),
);

$directory = new Directory(
Expand All @@ -59,6 +60,7 @@ public function process(CodeCoverage $coverage, string $target): void
$date,
$this->thresholds,
$coverage->collectsBranchAndPathCoverage(),
$this->colors->theme(),
);

$file = new File(
Expand All @@ -67,6 +69,7 @@ public function process(CodeCoverage $coverage, string $target): void
$date,
$this->thresholds,
$coverage->collectsBranchAndPathCoverage(),
$this->colors->theme(),
);

$directory->render($report, $target . 'index.html');
Expand Down Expand Up @@ -107,8 +110,7 @@ private function copyFiles(string $target): void
copy($this->templatePath . 'icons/file-directory.svg', $dir . 'file-directory.svg');

$dir = $this->directory($target . '_js');
copy($this->templatePath . 'js/bootstrap.min.js', $dir . 'bootstrap.min.js');
copy($this->templatePath . 'js/popper.min.js', $dir . 'popper.min.js');
copy($this->templatePath . 'js/bootstrap.bundle.min.js', $dir . 'bootstrap.bundle.min.js');
copy($this->templatePath . 'js/d3.min.js', $dir . 'd3.min.js');
copy($this->templatePath . 'js/jquery.min.js', $dir . 'jquery.min.js');
copy($this->templatePath . 'js/nv.d3.min.js', $dir . 'nv.d3.min.js');
Expand Down
5 changes: 4 additions & 1 deletion src/Report/Html/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ abstract class Renderer
protected Thresholds $thresholds;
protected bool $hasBranchCoverage;
protected string $version;
protected string $theme;

public function __construct(string $templatePath, string $generator, string $date, Thresholds $thresholds, bool $hasBranchCoverage)
public function __construct(string $templatePath, string $generator, string $date, Thresholds $thresholds, bool $hasBranchCoverage, string $theme)
{
$this->templatePath = $templatePath;
$this->generator = $generator;
$this->date = $date;
$this->thresholds = $thresholds;
$this->version = Version::id();
$this->hasBranchCoverage = $hasBranchCoverage;
$this->theme = $theme;
}

protected function renderItemTemplate(Template $template, array $data): string
Expand Down Expand Up @@ -173,6 +175,7 @@ protected function setCommonTemplateVariables(Template $template, AbstractNode $
'generator' => $this->generator,
'low_upper_bound' => $this->thresholds->lowUpperBound(),
'high_lower_bound' => $this->thresholds->highLowerBound(),
'theme' => $this->theme,
],
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Report/Html/Renderer/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ private function renderSourceWithLineCoverage(FileNode $node): string

if (!empty($popoverTitle)) {
$popover = sprintf(
' data-title="%s" data-content="%s" data-placement="top" data-html="true"',
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
$popoverTitle,
htmlspecialchars($popoverContent, $this->htmlSpecialCharsFlags),
);
Expand Down Expand Up @@ -635,7 +635,7 @@ private function renderSourceWithBranchCoverage(FileNode $node): string
$trClass = $lineCss . ' popin';

$popover = sprintf(
' data-title="%s" data-content="%s" data-placement="top" data-html="true"',
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
$popoverTitle,
htmlspecialchars($popoverContent, $this->htmlSpecialCharsFlags),
);
Expand Down Expand Up @@ -725,7 +725,7 @@ private function renderSourceWithPathCoverage(FileNode $node): string
$trClass = $lineCss . ' popin';

$popover = sprintf(
' data-title="%s" data-content="%s" data-placement="top" data-html="true"',
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
$popoverTitle,
htmlspecialchars($popoverContent, $this->htmlSpecialCharsFlags),
);
Expand Down Expand Up @@ -823,7 +823,7 @@ private function renderBranchLines(array $branch, array $codeLines, array $testD

if (!empty($popoverTitle)) {
$popover = sprintf(
' data-title="%s" data-content="%s" data-placement="top" data-html="true"',
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
$popoverTitle,
htmlspecialchars($popoverContent, $this->htmlSpecialCharsFlags),
);
Expand Down Expand Up @@ -938,7 +938,7 @@ private function renderPathLines(array $path, array $branches, array $codeLines,

if (!empty($popoverTitle)) {
$popover = sprintf(
' data-title="%s" data-content="%s" data-placement="top" data-html="true"',
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
$popoverTitle,
htmlspecialchars($popoverContent, $this->htmlSpecialCharsFlags),
);
Expand Down
2 changes: 1 addition & 1 deletion src/Report/Html/Renderer/Template/coverage_bar.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="progress">
<div class="progress-bar bg-{{level}}" role="progressbar" aria-valuenow="{{percent}}" aria-valuemin="0" aria-valuemax="100" style="width: {{percent}}%">
<span class="sr-only">{{percent}}% covered ({{level}})</span>
<span class="visually-hidden">{{percent}}% covered ({{level}})</span>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="progress">
<div class="progress-bar bg-{{level}}" role="progressbar" aria-valuenow="{{percent}}" aria-valuemin="0" aria-valuemax="100" style="width: {{percent}}%">
<span class="sr-only">{{percent}}% covered ({{level}})</span>
<span class="visually-hidden">{{percent}}% covered ({{level}})</span>
</div>
</div>
9 changes: 4 additions & 5 deletions src/Report/Html/Renderer/Template/css/bootstrap.min.css

Large diffs are not rendered by default.

53 changes: 32 additions & 21 deletions src/Report/Html/Renderer/Template/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,29 @@ body {
border: 0 !important;
}

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

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

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

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

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

.table tbody td.info {
background-color: #d9edf7;
/* background-color: #d9edf7; */
background-color: rgb(from var(--bs-info) r g b / 0.25);
}

td.big {
Expand All @@ -72,29 +73,35 @@ td.small {
}

td.codeLine {
font-family: "Source Code Pro", "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
/* font-family: "Source Code Pro", "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; */
font-family: "Source Code Pro", var(--bs-font-monospace);
white-space: pre-wrap;
}

td span.comment {
color: #888a85;
/* color: #888a85; */
color: var(--bs-secondary-color);
}

td span.default {
color: #2e3436;
/* color: #2e3436; */
color: var(--bs-body-color);
}

td span.html {
color: #888a85;
/* color: #888a85; */
color: var(--bs-secondary-color);
}

td span.keyword {
color: #2e3436;
/* color: #2e3436; */
color: var(--bs-body-color);
font-weight: bold;
}

pre span.string {
color: #2e3436;
/* color: #2e3436; */
color: var(--bs-body-color);
}

span.success, span.warning, span.danger {
Expand All @@ -112,10 +119,13 @@ span.success, span.warning, span.danger {
}

svg text {
font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
/* font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; */
font-family: var(--bs-font-sans-serif);
font-size: 11px;
color: #666;
fill: #666;
/* color: #666; */
color: var(--bs-gray);
/* fill: #666; */
fill: var(--bs-gray);
}

.scrollbox {
Expand All @@ -125,7 +135,8 @@ svg text {
}

table + .structure-heading {
border-top: 1px solid lightgrey;
/* border-top: 1px solid lightgrey; */
border-top: 1px solid var(--bs-gray-200);
padding-top: 0.5em;
}

Expand All @@ -137,22 +148,22 @@ table + .structure-heading {
text-align: center;
}

.covered-by-small-tests {
.covered-by-small-tests, tr.covered-by-small-tests td {
background-color: {{success-high}};
}

.covered-by-medium-tests {
.covered-by-medium-tests, tr.covered-by-medium-tests td {
background-color: {{success-medium}};
}

.covered-by-large-tests {
.covered-by-large-tests, tr.covered-by-large-tests td {
background-color: {{success-low}};
}

.not-covered {
.not-covered, tr.not-covered td {
background-color: {{danger}};
}

.not-coverable {
.not-coverable, tr.not-coverable td {
background-color: {{warning}};
}
2 changes: 1 addition & 1 deletion src/Report/Html/Renderer/Template/dashboard.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Dashboard for {{full_path}}</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Dashboard for {{full_path}}</title>
Expand Down
2 changes: 1 addition & 1 deletion src/Report/Html/Renderer/Template/directory.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down
5 changes: 2 additions & 3 deletions src/Report/Html/Renderer/Template/file.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down Expand Up @@ -58,8 +58,7 @@
</footer>
</div>
<script src="{{path_to_root}}_js/jquery.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/popper.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/bootstrap.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/bootstrap.bundle.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/file.js?v={{version}}" type="text/javascript"></script>
</body>
</html>
5 changes: 2 additions & 3 deletions src/Report/Html/Renderer/Template/file_branch.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down Expand Up @@ -60,8 +60,7 @@
</footer>
</div>
<script src="{{path_to_root}}_js/jquery.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/popper.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/bootstrap.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/bootstrap.bundle.min.js?v={{version}}" type="text/javascript"></script>
<script src="{{path_to_root}}_js/file.js?v={{version}}" type="text/javascript"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions src/Report/Html/Renderer/Template/js/bootstrap.bundle.min.js

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions src/Report/Html/Renderer/Template/js/bootstrap.min.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/Report/Html/Renderer/Template/js/jquery.min.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/Report/Html/Renderer/Template/js/popper.min.js

This file was deleted.

Loading
Loading