Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added branch coverage statistics to XML report
  • Loading branch information
chiefmyron committed Dec 13, 2024
commit f8dd6628a074501dfa69bdb9501e74f5e38e75e7
5 changes: 5 additions & 0 deletions src/Report/Xml/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ private function setTotals(AbstractNode $node, Totals $totals): void
$node->numberOfExecutedLines(),
);

$totals->setNumBranches(
$node->numberOfExecutableBranches(),
$node->numberOfExecutedBranches(),
);

$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 @@ -21,6 +21,7 @@
{
private DOMNode $container;
private DOMElement $linesNode;
private DOMElement $branchesNode;
private DOMElement $methodsNode;
private DOMElement $functionsNode;
private DOMElement $classesNode;
Expand All @@ -36,6 +37,11 @@ public function __construct(DOMElement $container)
'lines',
);

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

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

$container->appendChild($this->linesNode);
$container->appendChild($this->branchesNode);
$container->appendChild($this->methodsNode);
$container->appendChild($this->functionsNode);
$container->appendChild($this->classesNode);
Expand All @@ -81,6 +88,16 @@ public function setNumLines(int $loc, int $cloc, int $ncloc, int $executable, in
);
}

public function setNumBranches(int $count, int $tested): void
{
$this->branchesNode->setAttribute('count', (string) $count);
$this->branchesNode->setAttribute('tested', (string) $tested);
$this->branchesNode->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 @@ -3,6 +3,7 @@
<file name="BankAccount.php" path="%e">
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches 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 @@ -14,6 +14,7 @@
<directory name="%s">
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches 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 @@ -22,6 +23,7 @@
<file name="BankAccount.php" href="BankAccount.php.xml">
<totals>
<lines total="35" comments="0" code="35" executable="8" executed="5" percent="62.50"/>
<branches 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 @@ -11,6 +11,7 @@
<directory name="%s">
<totals>
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
<branches 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 @@ -19,6 +20,7 @@
<file name="source_with_class_and_anonymous_function.php" href="source_with_class_and_anonymous_function.php.xml">
<totals>
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
<branches 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 @@ -3,6 +3,7 @@
<file name="source_with_class_and_anonymous_function.php" path="%e">
<totals>
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
<branches 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 @@ -11,6 +11,7 @@
<directory name="%s">
<totals>
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
<branches 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 @@ -19,6 +20,7 @@
<file name="source_with_ignore.php" href="source_with_ignore.php.xml">
<totals>
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
<branches 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 @@ -3,6 +3,7 @@
<file name="source_with_ignore.php" path="%e">
<totals>
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
<branches 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
Loading