Skip to content

Commit f8dd662

Browse files
committed
Added branch coverage statistics to XML report
1 parent b36a500 commit f8dd662

File tree

11 files changed

+349
-0
lines changed

11 files changed

+349
-0
lines changed

src/Report/Xml/Facade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ private function setTotals(AbstractNode $node, Totals $totals): void
252252
$node->numberOfExecutedLines(),
253253
);
254254

255+
$totals->setNumBranches(
256+
$node->numberOfExecutableBranches(),
257+
$node->numberOfExecutedBranches(),
258+
);
259+
255260
$totals->setNumClasses(
256261
$node->numberOfClasses(),
257262
$node->numberOfTestedClasses(),

src/Report/Xml/Totals.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
{
2222
private DOMNode $container;
2323
private DOMElement $linesNode;
24+
private DOMElement $branchesNode;
2425
private DOMElement $methodsNode;
2526
private DOMElement $functionsNode;
2627
private DOMElement $classesNode;
@@ -36,6 +37,11 @@ public function __construct(DOMElement $container)
3637
'lines',
3738
);
3839

40+
$this->branchesNode = $dom->createElementNS(
41+
'https://schema.phpunit.de/coverage/1.0',
42+
'branches',
43+
);
44+
3945
$this->methodsNode = $dom->createElementNS(
4046
'https://schema.phpunit.de/coverage/1.0',
4147
'methods',
@@ -57,6 +63,7 @@ public function __construct(DOMElement $container)
5763
);
5864

5965
$container->appendChild($this->linesNode);
66+
$container->appendChild($this->branchesNode);
6067
$container->appendChild($this->methodsNode);
6168
$container->appendChild($this->functionsNode);
6269
$container->appendChild($this->classesNode);
@@ -81,6 +88,16 @@ public function setNumLines(int $loc, int $cloc, int $ncloc, int $executable, in
8188
);
8289
}
8390

91+
public function setNumBranches(int $count, int $tested): void
92+
{
93+
$this->branchesNode->setAttribute('count', (string) $count);
94+
$this->branchesNode->setAttribute('tested', (string) $tested);
95+
$this->branchesNode->setAttribute(
96+
'percent',
97+
$count === 0 ? '0' : sprintf('%01.2F', Percentage::fromFractionAndTotal($tested, $count)->asFloat()),
98+
);
99+
}
100+
84101
public function setNumClasses(int $count, int $tested): void
85102
{
86103
$this->classesNode->setAttribute('count', (string) $count);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<file name="BankAccount.php" path="%e">
44
<totals>
55
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
6+
<branches count="0" tested="0" percent="0"/>
67
<methods count="4" tested="3" percent="75.00"/>
78
<functions count="0" tested="0" percent="0"/>
89
<classes count="1" tested="0" percent="0.00"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<directory name="%s">
1515
<totals>
1616
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
17+
<branches count="0" tested="0" percent="0"/>
1718
<methods count="4" tested="3" percent="75.00"/>
1819
<functions count="0" tested="0" percent="0"/>
1920
<classes count="1" tested="0" percent="0.00"/>
@@ -22,6 +23,7 @@
2223
<file name="BankAccount.php" href="BankAccount.php.xml">
2324
<totals>
2425
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
26+
<branches count="0" tested="0" percent="0"/>
2527
<methods count="4" tested="3" percent="75.00"/>
2628
<functions count="0" tested="0" percent="0"/>
2729
<classes count="1" tested="0" percent="0.00"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<directory name="%s">
1212
<totals>
1313
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
14+
<branches count="0" tested="0" percent="0"/>
1415
<methods count="1" tested="1" percent="100.00"/>
1516
<functions count="0" tested="0" percent="0"/>
1617
<classes count="1" tested="1" percent="100.00"/>
@@ -19,6 +20,7 @@
1920
<file name="source_with_class_and_anonymous_function.php" href="source_with_class_and_anonymous_function.php.xml">
2021
<totals>
2122
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
23+
<branches count="0" tested="0" percent="0"/>
2224
<methods count="1" tested="1" percent="100.00"/>
2325
<functions count="0" tested="0" percent="0"/>
2426
<classes count="1" tested="1" percent="100.00"/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<file name="source_with_class_and_anonymous_function.php" path="%e">
44
<totals>
55
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
6+
<branches count="0" tested="0" percent="0"/>
67
<methods count="1" tested="1" percent="100.00"/>
78
<functions count="0" tested="0" percent="0"/>
89
<classes count="1" tested="1" percent="100.00"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<directory name="%s">
1212
<totals>
1313
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
14+
<branches count="0" tested="0" percent="0"/>
1415
<methods count="0" tested="0" percent="0"/>
1516
<functions count="1" tested="1" percent="100.00"/>
1617
<classes count="0" tested="0" percent="0"/>
@@ -19,6 +20,7 @@
1920
<file name="source_with_ignore.php" href="source_with_ignore.php.xml">
2021
<totals>
2122
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
23+
<branches count="0" tested="0" percent="0"/>
2224
<methods count="0" tested="0" percent="0"/>
2325
<functions count="1" tested="1" percent="100.00"/>
2426
<classes count="0" tested="0" percent="0"/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<file name="source_with_ignore.php" path="%e">
44
<totals>
55
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
6+
<branches count="0" tested="0" percent="0"/>
67
<methods count="0" tested="0" percent="0"/>
78
<functions count="1" tested="1" percent="100.00"/>
89
<classes count="0" tested="0" percent="0"/>

0 commit comments

Comments
 (0)