From f3b093f3694ee20d8554d819375ece64a2acde0a Mon Sep 17 00:00:00 2001 From: Andrew Patterson Date: Sat, 14 Dec 2024 01:16:49 +1100 Subject: [PATCH] Added path coverage statistics to XML report --- src/Report/Xml/Facade.php | 5 +++++ src/Report/Xml/Totals.php | 17 +++++++++++++++++ .../CoverageForBankAccount/BankAccount.php.xml | 1 + .../Report/XML/CoverageForBankAccount/index.xml | 2 ++ .../index.xml | 2 ++ ...ce_with_class_and_anonymous_function.php.xml | 1 + .../CoverageForFileWithIgnoredLines/index.xml | 2 ++ .../source_with_ignore.php.xml | 1 + .../BankAccount.php.xml | 1 + .../XML/PathCoverageForBankAccount/index.xml | 2 ++ 10 files changed, 34 insertions(+) diff --git a/src/Report/Xml/Facade.php b/src/Report/Xml/Facade.php index 9a05ec49..bae2bed6 100644 --- a/src/Report/Xml/Facade.php +++ b/src/Report/Xml/Facade.php @@ -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(), diff --git a/src/Report/Xml/Totals.php b/src/Report/Xml/Totals.php index d17692d0..ac15ae3c 100644 --- a/src/Report/Xml/Totals.php +++ b/src/Report/Xml/Totals.php @@ -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; @@ -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', @@ -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); @@ -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); diff --git a/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml b/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml index cea8aebe..7edc6e9c 100644 --- a/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml +++ b/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml @@ -4,6 +4,7 @@ + diff --git a/tests/_files/Report/XML/CoverageForBankAccount/index.xml b/tests/_files/Report/XML/CoverageForBankAccount/index.xml index 250af209..e479d6d7 100644 --- a/tests/_files/Report/XML/CoverageForBankAccount/index.xml +++ b/tests/_files/Report/XML/CoverageForBankAccount/index.xml @@ -15,6 +15,7 @@ + @@ -24,6 +25,7 @@ + diff --git a/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml index dc74a04e..5abb2122 100644 --- a/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml +++ b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml @@ -12,6 +12,7 @@ + @@ -21,6 +22,7 @@ + diff --git a/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml index 75199421..81a2b99c 100644 --- a/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml +++ b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml @@ -4,6 +4,7 @@ + diff --git a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml index 6af0b517..d136cc28 100644 --- a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml +++ b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml @@ -12,6 +12,7 @@ + @@ -21,6 +22,7 @@ + diff --git a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml index 6eb9c527..04b034d7 100644 --- a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml +++ b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml @@ -4,6 +4,7 @@ + diff --git a/tests/_files/Report/XML/PathCoverageForBankAccount/BankAccount.php.xml b/tests/_files/Report/XML/PathCoverageForBankAccount/BankAccount.php.xml index dcb59bf0..b29b437e 100644 --- a/tests/_files/Report/XML/PathCoverageForBankAccount/BankAccount.php.xml +++ b/tests/_files/Report/XML/PathCoverageForBankAccount/BankAccount.php.xml @@ -4,6 +4,7 @@ + diff --git a/tests/_files/Report/XML/PathCoverageForBankAccount/index.xml b/tests/_files/Report/XML/PathCoverageForBankAccount/index.xml index dec6939c..98b225bc 100644 --- a/tests/_files/Report/XML/PathCoverageForBankAccount/index.xml +++ b/tests/_files/Report/XML/PathCoverageForBankAccount/index.xml @@ -15,6 +15,7 @@ + @@ -24,6 +25,7 @@ +