From f5f9119b04d9536d4167a29a9397139107f9a039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Sm=C3=B3=C5=82kowski?= Date: Thu, 13 Mar 2025 13:19:08 +0100 Subject: [PATCH] Fix code coverage calculation to match coverage generated by `esi/phpunit-coverage-check` --- src/BadgeComposer.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/BadgeComposer.php b/src/BadgeComposer.php index 3a01e8b..19864c5 100644 --- a/src/BadgeComposer.php +++ b/src/BadgeComposer.php @@ -112,22 +112,26 @@ private function processFile(string $inputFile): void throw new Exception('Error reading file: ' . $inputFile); } $xml = new SimpleXMLElement($content); - $metrics = $xml->xpath('//metrics'); + $metrics = $xml->xpath('//project/metrics'); $totalConditionals = 0; $totalStatements = 0; $coveredStatements = 0; $coveredConditionals = 0; + $methods = 0; + $coveredMethods = 0; foreach ($metrics as $metric) { $totalConditionals += (int) $metric['conditionals']; $coveredConditionals += (int) $metric['coveredconditionals']; - $totalStatements += (int) $metric['statements']; - $coveredStatements += (int) $metric['coveredstatements']; + $totalStatements += (int) $metric['statements']; + $coveredStatements += (int) $metric['coveredstatements']; + $methods += (int) $metric['methods']; + $coveredMethods += (int) $metric['coveredmethods']; } - $totalElements = $totalConditionals + $totalStatements; - $coveredElements = $coveredConditionals + $coveredStatements; + $totalElements = $totalConditionals + $methods + $totalStatements; + $coveredElements = $coveredConditionals + $coveredMethods + $coveredStatements; $coverageRatio = $totalElements ? $coveredElements / $totalElements : 0; $this->totalCoverage[] = (int) round($coverageRatio * 100);