Skip to content

Commit ee59400

Browse files
Implement tab-based navigation between line coverage, branch coverage, and path coverage
1 parent aef6174 commit ee59400

8 files changed

Lines changed: 67 additions & 0 deletions

File tree

src/Report/Html/Renderer/File.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ public function render(FileNode $node, string $file): void
218218
],
219219
);
220220

221+
if ($this->hasBranchCoverage) {
222+
$template->setVar(
223+
['tabs' => $this->renderViewTabs($node->name(), 'line')],
224+
);
225+
}
226+
221227
try {
222228
$template->renderTo($file . '.html');
223229
} catch (Exception $e) {
@@ -231,6 +237,7 @@ public function render(FileNode $node, string $file): void
231237
if ($this->hasBranchCoverage) {
232238
$template->setVar(
233239
[
240+
'tabs' => $this->renderViewTabs($node->name(), 'branch'),
234241
'items' => $this->renderItems($node),
235242
'lines' => $this->renderSourceWithBranchCoverage($node),
236243
'legend' => '<p><span class="success"><strong>Fully covered</strong></span><span class="warning"><strong>Partially covered</strong></span><span class="danger"><strong>Not covered</strong></span></p>',
@@ -250,6 +257,7 @@ public function render(FileNode $node, string $file): void
250257

251258
$template->setVar(
252259
[
260+
'tabs' => $this->renderViewTabs($node->name(), 'path'),
253261
'items' => $this->renderItems($node),
254262
'lines' => $this->renderSourceWithPathCoverage($node),
255263
'legend' => '<p><span class="success"><strong>Fully covered</strong></span><span class="warning"><strong>Partially covered</strong></span><span class="danger"><strong>Not covered</strong></span></p>',
@@ -589,6 +597,34 @@ private function renderSourceWithLineCoverage(FileNode $node): string
589597
return $linesTemplate->render();
590598
}
591599

600+
private function renderViewTabs(string $fileName, string $activeView): string
601+
{
602+
$tabs = [
603+
'line' => ['href' => $fileName . '.html', 'label' => 'Line Coverage'],
604+
'branch' => ['href' => $fileName . '_branch.html', 'label' => 'Branch Coverage'],
605+
'path' => ['href' => $fileName . '_path.html', 'label' => 'Path Coverage'],
606+
];
607+
608+
$html = ' <ul class="nav nav-tabs mb-3">' . "\n";
609+
610+
foreach ($tabs as $view => $tab) {
611+
$active = $view === $activeView ? ' active' : '';
612+
$aria = $view === $activeView ? ' aria-current="page"' : '';
613+
614+
$html .= sprintf(
615+
' <li class="nav-item"><a class="nav-link%s" href="%s"%s>%s</a></li>' . "\n",
616+
$active,
617+
$tab['href'],
618+
$aria,
619+
$tab['label'],
620+
);
621+
}
622+
623+
$html .= ' </ul>';
624+
625+
return $html;
626+
}
627+
592628
private function renderSourceWithBranchCoverage(FileNode $node): string
593629
{
594630
$linesTemplate = new Template($this->templatePath . 'lines.html.dist', '{{', '}}');

src/Report/Html/Renderer/Template/file_branch.html.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</div>
2525
</header>
2626
<div class="container-fluid">
27+
{{tabs}}
2728
<div class="table-responsive">
2829
<table class="table table-bordered">
2930
<thead>

tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
</div>
2727
</header>
2828
<div class="container-fluid">
29+
<ul class="nav nav-tabs mb-3">
30+
<li class="nav-item"><a class="nav-link active" href="BankAccount.php.html" aria-current="page">Line Coverage</a></li>
31+
<li class="nav-item"><a class="nav-link" href="BankAccount.php_branch.html">Branch Coverage</a></li>
32+
<li class="nav-item"><a class="nav-link" href="BankAccount.php_path.html">Path Coverage</a></li>
33+
</ul>
2934
<div class="table-responsive">
3035
<table class="table table-bordered">
3136
<thead>

tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_branch.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
</div>
2727
</header>
2828
<div class="container-fluid">
29+
<ul class="nav nav-tabs mb-3">
30+
<li class="nav-item"><a class="nav-link" href="BankAccount.php.html">Line Coverage</a></li>
31+
<li class="nav-item"><a class="nav-link active" href="BankAccount.php_branch.html" aria-current="page">Branch Coverage</a></li>
32+
<li class="nav-item"><a class="nav-link" href="BankAccount.php_path.html">Path Coverage</a></li>
33+
</ul>
2934
<div class="table-responsive">
3035
<table class="table table-bordered">
3136
<thead>

tests/_files/Report/HTML/PathCoverageForBankAccount/BankAccount.php_path.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
</div>
2727
</header>
2828
<div class="container-fluid">
29+
<ul class="nav nav-tabs mb-3">
30+
<li class="nav-item"><a class="nav-link" href="BankAccount.php.html">Line Coverage</a></li>
31+
<li class="nav-item"><a class="nav-link" href="BankAccount.php_branch.html">Branch Coverage</a></li>
32+
<li class="nav-item"><a class="nav-link active" href="BankAccount.php_path.html" aria-current="page">Path Coverage</a></li>
33+
</ul>
2934
<div class="table-responsive">
3035
<table class="table table-bordered">
3136
<thead>

tests/_files/Report/HTML/PathCoverageForSourceWithoutNamespace/source_without_namespace.php.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
</div>
2727
</header>
2828
<div class="container-fluid">
29+
<ul class="nav nav-tabs mb-3">
30+
<li class="nav-item"><a class="nav-link active" href="source_without_namespace.php.html" aria-current="page">Line Coverage</a></li>
31+
<li class="nav-item"><a class="nav-link" href="source_without_namespace.php_branch.html">Branch Coverage</a></li>
32+
<li class="nav-item"><a class="nav-link" href="source_without_namespace.php_path.html">Path Coverage</a></li>
33+
</ul>
2934
<div class="table-responsive">
3035
<table class="table table-bordered">
3136
<thead>

tests/_files/Report/HTML/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_branch.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
</div>
2727
</header>
2828
<div class="container-fluid">
29+
<ul class="nav nav-tabs mb-3">
30+
<li class="nav-item"><a class="nav-link" href="source_without_namespace.php.html">Line Coverage</a></li>
31+
<li class="nav-item"><a class="nav-link active" href="source_without_namespace.php_branch.html" aria-current="page">Branch Coverage</a></li>
32+
<li class="nav-item"><a class="nav-link" href="source_without_namespace.php_path.html">Path Coverage</a></li>
33+
</ul>
2934
<div class="table-responsive">
3035
<table class="table table-bordered">
3136
<thead>

tests/_files/Report/HTML/PathCoverageForSourceWithoutNamespace/source_without_namespace.php_path.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
</div>
2727
</header>
2828
<div class="container-fluid">
29+
<ul class="nav nav-tabs mb-3">
30+
<li class="nav-item"><a class="nav-link" href="source_without_namespace.php.html">Line Coverage</a></li>
31+
<li class="nav-item"><a class="nav-link" href="source_without_namespace.php_branch.html">Branch Coverage</a></li>
32+
<li class="nav-item"><a class="nav-link active" href="source_without_namespace.php_path.html" aria-current="page">Path Coverage</a></li>
33+
</ul>
2934
<div class="table-responsive">
3035
<table class="table table-bordered">
3136
<thead>

0 commit comments

Comments
 (0)