Skip to content

Commit 0428086

Browse files
committed
preparing 2.0.2 release
1 parent 63b8d4d commit 0428086

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.2] - 2024-12-03
9+
10+
### Changed
11+
12+
* Updated total coverage calculation within the CoverageCheck::processByFile() method, as it was producing different totals than the normal process method.
13+
* Now relies on total elements and total covered elements, instead of gathering percent coverage for each file and dividing by file count.
14+
* Updated unit test(s) accordingly
15+
16+
817
## [2.0.1] - 2024-10-09
918

1019
### Added
@@ -123,6 +132,7 @@ This initial version is forked from [rregeer/phpunit-coverage-check](https://git
123132

124133

125134
[unreleased]: https://github.com/ericsizemore/phpunit-coverage-check/tree/master
135+
[2.0.2]: https://github.com/ericsizemore/phpunit-coverage-check/releases/tag/2.0.2
126136
[2.0.1]: https://github.com/ericsizemore/phpunit-coverage-check/releases/tag/2.0.1
127137
[2.0.0]: https://github.com/ericsizemore/phpunit-coverage-check/releases/tag/2.0.0
128138
[1.0.0]: https://github.com/ericsizemore/phpunit-coverage-check/releases/tag/1.0.0

src/CoverageCheck.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public function process(): false|float
130130
if ($rawMetrics === false) {
131131
return false;
132132
}
133+
133134
//@codeCoverageIgnoreEnd
134135

135136
/**
@@ -169,8 +170,9 @@ public function process(): false|float
169170
*/
170171
public function processByFile(): array|false
171172
{
172-
$fileMetrics = [];
173-
$totalCoverage = 0;
173+
$fileMetrics = [];
174+
$totalElementsCovered = 0;
175+
$totalElements = 0;
174176

175177
$rawMetrics = $this->loadMetrics(self::XPATH_FILES) ?? false;
176178

@@ -197,7 +199,8 @@ public function processByFile(): array|false
197199
}
198200

199201
$coveragePercentage = $coveredMetrics / $totalMetrics * 100;
200-
$totalCoverage += $coveragePercentage;
202+
$totalElementsCovered += $coveredMetrics;
203+
$totalElements += $totalMetrics;
201204

202205
$fileMetrics[(string) $file['name']] = [
203206
'coveredMetrics' => $coveredMetrics,
@@ -208,15 +211,11 @@ public function processByFile(): array|false
208211

209212
unset($rawMetrics);
210213

211-
$fileCount = \count($fileMetrics);
212-
213-
if ($fileCount === 0) {
214+
if ($totalElements === 0) {
214215
return false;
215216
}
216217

217-
if ($totalCoverage !== 0) {
218-
$totalCoverage /= $fileCount;
219-
}
218+
$totalCoverage = $totalElementsCovered / $totalElements * 100;
220219

221220
return [
222221
'fileMetrics' => $fileMetrics,

tests/src/Command/CoverageCheckCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ public function testShowFilesTableOutputBelowThreshold(): void
301301
{
302302
$this->tester->run([
303303
'cloverfile' => self::$fixtures['valid'],
304-
'threshold' => 90,
304+
'threshold' => 91,
305305
'--show-files' => true,
306306
]);
307307

308308
self::assertSame(self::$fixtures['valid'], $this->tester->getInput()->getArgument('cloverfile'));
309-
self::assertSame(90, $this->tester->getInput()->getArgument('threshold'));
309+
self::assertSame(91, $this->tester->getInput()->getArgument('threshold'));
310310

311311
$eol = PHP_EOL;
312312

@@ -316,7 +316,7 @@ public function testShowFilesTableOutputBelowThreshold(): void
316316
$expected .= ' /tmp/Example/String.php 36/38 94.74% ' . $eol;
317317
$expected .= ' /tmp/Example/StringList.php 20/24 83.33% ' . $eol;
318318
$expected .= ' ----------------------------- -------------------------- ---------- ' . $eol;
319-
$expected .= ' Overall Totals 56/62 89.04% ' . $eol;
319+
$expected .= ' Overall Totals 56/62 90.32% ' . $eol;
320320
$expected .= ' ----------------------------- -------------------------- ----------';
321321

322322
self::assertEquals($expected, trim($this->tester->getDisplay()));

0 commit comments

Comments
 (0)