Skip to content

Commit 12663ff

Browse files
Implement tab-based navigation between line coverage, branch coverage, and path coverage
1 parent 24dc6fc commit 12663ff

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
@@ -220,6 +220,12 @@ public function render(FileNode $node, string $file): void
220220
],
221221
);
222222

223+
if ($this->hasBranchCoverage) {
224+
$template->setVar(
225+
['tabs' => $this->renderViewTabs($node->name(), 'line')],
226+
);
227+
}
228+
223229
try {
224230
$template->renderTo($file . '.html');
225231
} catch (Exception $e) {
@@ -233,6 +239,7 @@ public function render(FileNode $node, string $file): void
233239
if ($this->hasBranchCoverage) {
234240
$template->setVar(
235241
[
242+
'tabs' => $this->renderViewTabs($node->name(), 'branch'),
236243
'items' => $this->renderItems($node),
237244
'lines' => $this->renderSourceWithBranchCoverage($node),
238245
'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>',
@@ -252,6 +259,7 @@ public function render(FileNode $node, string $file): void
252259

253260
$template->setVar(
254261
[
262+
'tabs' => $this->renderViewTabs($node->name(), 'path'),
255263
'items' => $this->renderItems($node),
256264
'lines' => $this->renderSourceWithPathCoverage($node),
257265
'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>',
@@ -591,6 +599,34 @@ private function renderSourceWithLineCoverage(FileNode $node): string
591599
return $linesTemplate->render();
592600
}
593601

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