Skip to content

Commit

Permalink
Added path coverage statistics to XML report
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefmyron committed Dec 13, 2024
1 parent f8dd662 commit f3b093f
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Report/Xml/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ private function setTotals(AbstractNode $node, Totals $totals): void
$node->numberOfExecutedBranches(),
);

$totals->setNumPaths(
$node->numberOfExecutablePaths(),
$node->numberOfExecutedPaths(),
);

$totals->setNumClasses(
$node->numberOfClasses(),
$node->numberOfTestedClasses(),
Expand Down
17 changes: 17 additions & 0 deletions src/Report/Xml/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
private DOMNode $container;
private DOMElement $linesNode;
private DOMElement $branchesNode;
private DOMElement $pathsNode;
private DOMElement $methodsNode;
private DOMElement $functionsNode;
private DOMElement $classesNode;
Expand All @@ -42,6 +43,11 @@ public function __construct(DOMElement $container)
'branches',
);

$this->pathsNode = $dom->createElementNS(
'https://schema.phpunit.de/coverage/1.0',
'paths',
);

$this->methodsNode = $dom->createElementNS(
'https://schema.phpunit.de/coverage/1.0',
'methods',
Expand All @@ -64,6 +70,7 @@ public function __construct(DOMElement $container)

$container->appendChild($this->linesNode);
$container->appendChild($this->branchesNode);
$container->appendChild($this->pathsNode);
$container->appendChild($this->methodsNode);
$container->appendChild($this->functionsNode);
$container->appendChild($this->classesNode);
Expand Down Expand Up @@ -98,6 +105,16 @@ public function setNumBranches(int $count, int $tested): void
);
}

public function setNumPaths(int $count, int $tested): void
{
$this->pathsNode->setAttribute('count', (string) $count);
$this->pathsNode->setAttribute('tested', (string) $tested);
$this->pathsNode->setAttribute(
'percent',
$count === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($tested, $count)->asFloat()),
);
}

public function setNumClasses(int $count, int $tested): void
{
$this->classesNode->setAttribute('count', (string) $count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="4" tested="3" percent="75.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="0" percent="0.00"/>
Expand Down
2 changes: 2 additions & 0 deletions tests/_files/Report/XML/CoverageForBankAccount/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="4" tested="3" percent="75.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="0" percent="0.00"/>
Expand All @@ -24,6 +25,7 @@
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="4" tested="3" percent="75.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="0" percent="0.00"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<totals>
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="1" tested="1" percent="100.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="1" percent="100.00"/>
Expand All @@ -21,6 +22,7 @@
<totals>
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="1" tested="1" percent="100.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="1" percent="100.00"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<totals>
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="1" tested="1" percent="100.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="1" percent="100.00"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<totals>
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="0" tested="0" percent="0"/>
<functions count="1" tested="1" percent="100.00"/>
<classes count="0" tested="0" percent="0"/>
Expand All @@ -21,6 +22,7 @@
<totals>
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="0" tested="0" percent="0"/>
<functions count="1" tested="1" percent="100.00"/>
<classes count="0" tested="0" percent="0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<totals>
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
<branches count="0" tested="0" percent="0"/>
<paths count="0" tested="0" percent="0"/>
<methods count="0" tested="0" percent="0"/>
<functions count="1" tested="1" percent="100.00"/>
<classes count="0" tested="0" percent="0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches count="7" tested="3" percent="42.86"/>
<paths count="5" tested="3" percent="60.00"/>
<methods count="4" tested="3" percent="75.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="0" percent="0.00"/>
Expand Down
2 changes: 2 additions & 0 deletions tests/_files/Report/XML/PathCoverageForBankAccount/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches count="7" tested="3" percent="42.86"/>
<paths count="5" tested="3" percent="60.00"/>
<methods count="4" tested="3" percent="75.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="0" percent="0.00"/>
Expand All @@ -24,6 +25,7 @@
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches count="7" tested="3" percent="42.86"/>
<paths count="5" tested="3" percent="60.00"/>
<methods count="4" tested="3" percent="75.00"/>
<functions count="0" tested="0" percent="0"/>
<classes count="1" tested="0" percent="0.00"/>
Expand Down

0 comments on commit f3b093f

Please sign in to comment.