Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add branch coverage stats to xml report #1057

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions src/Report/Xml/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ private function setTotals(AbstractNode $node, Totals $totals): void
$node->numberOfExecutedLines(),
);

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

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

$totals->setNumClasses(
$node->numberOfClasses(),
$node->numberOfTestedClasses(),
Expand Down
34 changes: 34 additions & 0 deletions src/Report/Xml/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
{
private DOMNode $container;
private DOMElement $linesNode;
private DOMElement $branchesNode;
private DOMElement $pathsNode;
private DOMElement $methodsNode;
private DOMElement $functionsNode;
private DOMElement $classesNode;
Expand All @@ -36,6 +38,16 @@ public function __construct(DOMElement $container)
'lines',
);

$this->branchesNode = $dom->createElementNS(
'https://schema.phpunit.de/coverage/1.0',
'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 @@ -57,6 +69,8 @@ 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 All @@ -81,6 +95,26 @@ 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 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 @@ -3,6 +3,8 @@
<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"/>
<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
4 changes: 4 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,8 @@
<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"/>
<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 @@ -22,6 +24,8 @@
<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"/>
<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 @@ -11,6 +11,8 @@
<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"/>
<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 @@ -19,6 +21,8 @@
<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"/>
<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 @@ -3,6 +3,8 @@
<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"/>
<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 @@ -11,6 +11,8 @@
<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"/>
<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 @@ -19,6 +21,8 @@
<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"/>
<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 @@ -3,6 +3,8 @@
<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"/>
<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
Loading
Loading