Skip to content

Commit f3b093f

Browse files
committed
Added path coverage statistics to XML report
1 parent f8dd662 commit f3b093f

File tree

10 files changed

+34
-0
lines changed

10 files changed

+34
-0
lines changed

src/Report/Xml/Facade.php

+5
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ private function setTotals(AbstractNode $node, Totals $totals): void
257257
$node->numberOfExecutedBranches(),
258258
);
259259

260+
$totals->setNumPaths(
261+
$node->numberOfExecutablePaths(),
262+
$node->numberOfExecutedPaths(),
263+
);
264+
260265
$totals->setNumClasses(
261266
$node->numberOfClasses(),
262267
$node->numberOfTestedClasses(),

src/Report/Xml/Totals.php

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
private DOMNode $container;
2323
private DOMElement $linesNode;
2424
private DOMElement $branchesNode;
25+
private DOMElement $pathsNode;
2526
private DOMElement $methodsNode;
2627
private DOMElement $functionsNode;
2728
private DOMElement $classesNode;
@@ -42,6 +43,11 @@ public function __construct(DOMElement $container)
4243
'branches',
4344
);
4445

46+
$this->pathsNode = $dom->createElementNS(
47+
'https://schema.phpunit.de/coverage/1.0',
48+
'paths',
49+
);
50+
4551
$this->methodsNode = $dom->createElementNS(
4652
'https://schema.phpunit.de/coverage/1.0',
4753
'methods',
@@ -64,6 +70,7 @@ public function __construct(DOMElement $container)
6470

6571
$container->appendChild($this->linesNode);
6672
$container->appendChild($this->branchesNode);
73+
$container->appendChild($this->pathsNode);
6774
$container->appendChild($this->methodsNode);
6875
$container->appendChild($this->functionsNode);
6976
$container->appendChild($this->classesNode);
@@ -98,6 +105,16 @@ public function setNumBranches(int $count, int $tested): void
98105
);
99106
}
100107

108+
public function setNumPaths(int $count, int $tested): void
109+
{
110+
$this->pathsNode->setAttribute('count', (string) $count);
111+
$this->pathsNode->setAttribute('tested', (string) $tested);
112+
$this->pathsNode->setAttribute(
113+
'percent',
114+
$count === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($tested, $count)->asFloat()),
115+
);
116+
}
117+
101118
public function setNumClasses(int $count, int $tested): void
102119
{
103120
$this->classesNode->setAttribute('count', (string) $count);

tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<totals>
55
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
66
<branches count="0" tested="0" percent="0"/>
7+
<paths count="0" tested="0" percent="0"/>
78
<methods count="4" tested="3" percent="75.00"/>
89
<functions count="0" tested="0" percent="0"/>
910
<classes count="1" tested="0" percent="0.00"/>

tests/_files/Report/XML/CoverageForBankAccount/index.xml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<totals>
1616
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
1717
<branches count="0" tested="0" percent="0"/>
18+
<paths count="0" tested="0" percent="0"/>
1819
<methods count="4" tested="3" percent="75.00"/>
1920
<functions count="0" tested="0" percent="0"/>
2021
<classes count="1" tested="0" percent="0.00"/>
@@ -24,6 +25,7 @@
2425
<totals>
2526
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
2627
<branches count="0" tested="0" percent="0"/>
28+
<paths count="0" tested="0" percent="0"/>
2729
<methods count="4" tested="3" percent="75.00"/>
2830
<functions count="0" tested="0" percent="0"/>
2931
<classes count="1" tested="0" percent="0.00"/>

tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<totals>
1313
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
1414
<branches count="0" tested="0" percent="0"/>
15+
<paths count="0" tested="0" percent="0"/>
1516
<methods count="1" tested="1" percent="100.00"/>
1617
<functions count="0" tested="0" percent="0"/>
1718
<classes count="1" tested="1" percent="100.00"/>
@@ -21,6 +22,7 @@
2122
<totals>
2223
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
2324
<branches count="0" tested="0" percent="0"/>
25+
<paths count="0" tested="0" percent="0"/>
2426
<methods count="1" tested="1" percent="100.00"/>
2527
<functions count="0" tested="0" percent="0"/>
2628
<classes count="1" tested="1" percent="100.00"/>

tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<totals>
55
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
66
<branches count="0" tested="0" percent="0"/>
7+
<paths count="0" tested="0" percent="0"/>
78
<methods count="1" tested="1" percent="100.00"/>
89
<functions count="0" tested="0" percent="0"/>
910
<classes count="1" tested="1" percent="100.00"/>

tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<totals>
1313
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
1414
<branches count="0" tested="0" percent="0"/>
15+
<paths count="0" tested="0" percent="0"/>
1516
<methods count="0" tested="0" percent="0"/>
1617
<functions count="1" tested="1" percent="100.00"/>
1718
<classes count="0" tested="0" percent="0"/>
@@ -21,6 +22,7 @@
2122
<totals>
2223
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
2324
<branches count="0" tested="0" percent="0"/>
25+
<paths count="0" tested="0" percent="0"/>
2426
<methods count="0" tested="0" percent="0"/>
2527
<functions count="1" tested="1" percent="100.00"/>
2628
<classes count="0" tested="0" percent="0"/>

tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<totals>
55
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
66
<branches count="0" tested="0" percent="0"/>
7+
<paths count="0" tested="0" percent="0"/>
78
<methods count="0" tested="0" percent="0"/>
89
<functions count="1" tested="1" percent="100.00"/>
910
<classes count="0" tested="0" percent="0"/>

tests/_files/Report/XML/PathCoverageForBankAccount/BankAccount.php.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<totals>
55
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
66
<branches count="7" tested="3" percent="42.86"/>
7+
<paths count="5" tested="3" percent="60.00"/>
78
<methods count="4" tested="3" percent="75.00"/>
89
<functions count="0" tested="0" percent="0"/>
910
<classes count="1" tested="0" percent="0.00"/>

tests/_files/Report/XML/PathCoverageForBankAccount/index.xml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<totals>
1616
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
1717
<branches count="7" tested="3" percent="42.86"/>
18+
<paths count="5" tested="3" percent="60.00"/>
1819
<methods count="4" tested="3" percent="75.00"/>
1920
<functions count="0" tested="0" percent="0"/>
2021
<classes count="1" tested="0" percent="0.00"/>
@@ -24,6 +25,7 @@
2425
<totals>
2526
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
2627
<branches count="7" tested="3" percent="42.86"/>
28+
<paths count="5" tested="3" percent="60.00"/>
2729
<methods count="4" tested="3" percent="75.00"/>
2830
<functions count="0" tested="0" percent="0"/>
2931
<classes count="1" tested="0" percent="0.00"/>

0 commit comments

Comments
 (0)