Skip to content

Commit 652a598

Browse files
authored
Merge pull request #16 from Aeliot-Tm/fix_report_row_comparing
Fix code coverage report
2 parents ade581e + 5cd9dc7 commit 652a598

File tree

13 files changed

+223
-55
lines changed

13 files changed

+223
-55
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,17 @@ jobs:
3737

3838
- uses: actions/checkout@v3
3939

40-
- name: Set versions
41-
run: |
42-
sed -i 's/\^3.4|\^4.0|\^5.0|\^6.0/${{ matrix.symfony-version }}/g' composer.json
43-
sed -i 's/\^7.5|\^9.5/${{ matrix.phpunit-version }}/g' composer.json
44-
4540
- name: Validate composer.json and composer.lock
4641
run: composer validate --strict
4742

48-
- name: Cache Composer packages
49-
id: composer-cache
50-
uses: actions/cache@v3
51-
with:
52-
path: vendor
53-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
54-
restore-keys: |
55-
${{ runner.os }}-php-
43+
- name: Set versions
44+
run: composer run-script set_versions ${{ matrix.symfony-version }} ${{ matrix.phpunit-version }}
5645

5746
- name: Install dependencies
5847
uses: ramsey/composer-install@v2
5948

6049
- name: Run test suite
61-
run: composer run-script test
50+
run: composer run-script phpunit
6251

6352
phpstan:
6453
runs-on: ubuntu-latest
@@ -69,17 +58,8 @@ jobs:
6958

7059
- uses: actions/checkout@v3
7160

72-
- name: Cache Composer packages
73-
id: composer-cache
74-
uses: actions/cache@v3
75-
with:
76-
path: vendor
77-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
78-
restore-keys: |
79-
${{ runner.os }}-php-
80-
8161
- name: Install dependencies
8262
uses: ramsey/composer-install@v2
8363

8464
- name: PHPStan analyse
85-
run: vendor/bin/phpstan analyse
65+
run: composer run-script phpstan-analise

CHANGELOG.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
CHANGELOG
2+
=========
3+
4+
2.0.1
5+
-----
6+
* Bug fixes:
7+
* Fix comparing and displaying of data used for comparing of Clover code coverage report with its baseline.
8+
* Minors:
9+
* Configure matrix for better dependencies testing.
10+
* Update scripts in composer config and running of them on GitGub Actions.
11+
* Added script to replace required versions of packages.
12+
13+
2.0.0
14+
-----
15+
* Feature:
16+
* Changed format of Clover code coverage baseline to improve its readability.
17+
* Added support for old version of Clover code coverage baseline.
18+
* Backward compatibility breaks:
19+
* Used package `symfony/console` instead of custom console calls handling.
20+
* Deprecations:
21+
* Scripts `bin/pccb_clover_build_baseline` and `bin/pccb_clover_compare` are deprecated.
22+
Single script `bin/pccb` should be used for all commands calls.
23+
* Minors:
24+
* Configured Docker for dev purposes.
25+
26+
1.1.0
27+
-----
28+
* Features:
29+
* Beautified report of clover baseline comparing results when used option "verbose".
30+
* Added compatibility with PHP 7.1.
31+
* Minors:
32+
* Added check by PHPStan.
33+
34+
1.0.0
35+
-----
36+
* Features:
37+
* Implemented baseline builder.
38+
* Minors:
39+
* Code refactored in OOP approach.
40+
* Removed messages about fallback to the default options values.
41+
* Configured running of automated tests on GitHub.
42+
43+
0.1
44+
---
45+
* Features:
46+
* Initial implementation of baseline comparing.

bin/dev/set_composer_versions

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
SYMFONY_NEW_VERSION=$1
6+
PHPUNIT_NEW_VERSION=$2
7+
8+
sed -i "s/\^3.4|\^4.0|\^5.0|\^6.0/${SYMFONY_NEW_VERSION}/g" composer.json
9+
sed -i "s/\^7.5|\^9.5/${PHPUNIT_NEW_VERSION}/g" composer.json

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@
4444
"phpunit/phpunit": "^7.5|^9.5"
4545
},
4646
"scripts": {
47-
"test": "vendor/bin/phpunit",
48-
"phpstan-analise": "vendor/bin/phpstan analyse"
47+
"test": [
48+
"@phpunit",
49+
"@phpstan-analise"
50+
],
51+
"phpunit": "vendor/bin/phpunit",
52+
"phpstan-analise": "vendor/bin/phpstan analyse",
53+
"phpstan-update": "vendor/bin/phpstan analyse --generate-baseline phpstan-baseline.neon",
54+
"set_versions": "sh bin/dev/set_composer_versions"
4955
},
5056
"suggest": {
5157
"phpunit/phpunit": "PHPUnit must be used to generate code coverage report."

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ parameters:
1515
count: 2
1616
path: tests/Unit/ComparatorTest.php
1717

18+
-
19+
message: "#^Trying to mock an undefined method read\\(\\) on class \\.$#"
20+
count: 2
21+
path: tests/Unit/ComparatorTest.php
22+
1823
-
1924
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
2025
count: 1
2126
path: tests/Unit/Model/ConsoleTableTest.php
2227

28+
-
29+
message: "#^Trying to mock an undefined method getValues\\(\\) on class \\.$#"
30+
count: 1
31+
path: tests/Unit/Model/ConsoleTableTest.php
32+
2333
-
2434
message: "#^Expression \"\\$coverage\\['any_key'\\]\" on a separate line does not do anything\\.$#"
2535
count: 2

src/Model/ComparingRow.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ final class ComparingRow
2929
public function __construct(string $name, float $old, float $new)
3030
{
3131
$this->name = $name;
32-
$this->old = round($old * 100, 2);
33-
$this->new = round($new * 100, 2);
32+
$this->old = round($old, 2);
33+
$this->new = round($new, 2);
3434
$this->progress = $this->new - $this->old;
3535
}
3636

@@ -58,9 +58,14 @@ public function getValues(): array
5858

5959
return [
6060
'name' => $this->name,
61-
'old' => str_pad(number_format($this->old, 2), 6, ' ', \STR_PAD_LEFT) . ' %',
62-
'new' => str_pad(number_format($this->new, 2), 6, ' ', \STR_PAD_LEFT) . ' %',
63-
'progress' => str_pad($progressPrefix . number_format($this->progress, 2), 7, ' ', \STR_PAD_LEFT) . ' %',
61+
'old' => $this->formatPercentage($this->old, 6),
62+
'new' => $this->formatPercentage($this->new, 6),
63+
'progress' => $this->formatPercentage($this->progress, 7, $progressPrefix),
6464
];
6565
}
66+
67+
private function formatPercentage(float $value, int $length, string $prefix = ''): string
68+
{
69+
return str_pad($prefix . number_format($value, 2, '.', ''), $length, ' ', \STR_PAD_LEFT) . ' %';
70+
}
6671
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Aeliot\PHPUnitCodeCoverageBaseline\Test\Functional\Command;
6+
7+
use Aeliot\PHPUnitCodeCoverageBaseline\Test\Functional\FunctionalTestCase;
8+
9+
final class CloverCompareCommandTest extends FunctionalTestCase
10+
{
11+
public function testPositiveFlow(): void
12+
{
13+
$command = 'php ' . __DIR__ . '/../../../bin/pccb'
14+
. ' pccb:clover:compare -vv'
15+
. ' -b tests/fixtures/baseline/baseline_v2.json'
16+
. ' -c tests/fixtures/clover/clover.xml';
17+
exec($command, $output, $resultCode);
18+
19+
$expected = <<<OUTPUT
20+
|--------------|--------------|--------------|-----------|
21+
| Metrics | Old coverage | New coverage | Progress |
22+
|--------------|--------------|--------------|-----------|
23+
| methods | 1.00 % | 50.00 % | +49.00 % |
24+
| conditionals | 30.00 % | 75.00 % | +45.00 % |
25+
| statements | 50.00 % | 83.33 % | +33.33 % |
26+
| elements | 70.00 % | 87.50 % | +17.50 % |
27+
|--------------|--------------|--------------|-----------|
28+
29+
Good job! You improved code coverage. Update baseline.
30+
OUTPUT;
31+
32+
self::assertEquals(0, $resultCode);
33+
self::assertEquals($expected, implode(PHP_EOL, $output));
34+
}
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Aeliot\PHPUnitCodeCoverageBaseline\Test\Functional;
6+
7+
use Aeliot\PHPUnitCodeCoverageBaseline\Test\Unit\UnitTestCase;
8+
9+
abstract class FunctionalTestCase extends UnitTestCase
10+
{
11+
12+
}

tests/Integration/ComparatorTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Aeliot\PHPUnitCodeCoverageBaseline\Test\Integration;
6+
7+
use Aeliot\PHPUnitCodeCoverageBaseline\BaselineReaderFactory;
8+
use Aeliot\PHPUnitCodeCoverageBaseline\Comparator;
9+
use Aeliot\PHPUnitCodeCoverageBaseline\Model\ComparingRow;
10+
use Aeliot\PHPUnitCodeCoverageBaseline\Reader\CloverReader;
11+
12+
final class ComparatorTest extends IntegrationTestCase
13+
{
14+
public function testRowsValues(): void
15+
{
16+
$expected = [
17+
[
18+
'name' => 'methods',
19+
'old' => ' 1.00 %',
20+
'new' => ' 50.00 %',
21+
'progress' => ' +49.00 %',
22+
],
23+
[
24+
'name' => 'conditionals',
25+
'old' => ' 30.00 %',
26+
'new' => ' 75.00 %',
27+
'progress' => ' +45.00 %',
28+
],
29+
[
30+
'name' => 'statements',
31+
'old' => ' 50.00 %',
32+
'new' => ' 83.33 %',
33+
'progress' => ' +33.33 %',
34+
],
35+
[
36+
'name' => 'elements',
37+
'old' => ' 70.00 %',
38+
'new' => ' 87.50 %',
39+
'progress' => ' +17.50 %',
40+
],
41+
];
42+
$baselinePath = __DIR__ . '/../fixtures/baseline/baseline_v2.json';
43+
$baselineReader = (new BaselineReaderFactory())->createReader($baselinePath);
44+
$cloverPath = __DIR__ . '/../fixtures/clover/clover.xml';
45+
$cloverReader = new CloverReader($cloverPath);
46+
$results = (new Comparator($baselineReader, $cloverReader))->compare();
47+
$actual = array_map(static function (ComparingRow $row): array {
48+
return $row->getValues();
49+
}, $results->getRows());
50+
51+
self::assertEquals($expected, $actual);
52+
}
53+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Aeliot\PHPUnitCodeCoverageBaseline\Test\Integration;
6+
7+
use Aeliot\PHPUnitCodeCoverageBaseline\Test\Unit\UnitTestCase;
8+
9+
abstract class IntegrationTestCase extends UnitTestCase
10+
{
11+
12+
}

tests/Unit/Model/ComparingRowTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable
5252
yield 'no changes' => [
5353
[
5454
'name' => 'any string',
55-
'old' => ' 10.00 %',
56-
'new' => ' 10.00 %',
55+
'old' => ' 0.10 %',
56+
'new' => ' 0.10 %',
5757
'progress' => ' 0.00 %',
5858
],
5959
0.1,
@@ -68,7 +68,7 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable
6868
'progress' => '+100.00 %',
6969
],
7070
0.0,
71-
1.0,
71+
100.0,
7272
];
7373

7474
yield '-100 %' => [
@@ -78,7 +78,7 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable
7878
'new' => ' 0.00 %',
7979
'progress' => '-100.00 %',
8080
],
81-
1.0,
81+
100.0,
8282
0.0,
8383
];
8484

@@ -89,8 +89,8 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable
8989
'new' => ' 0.10 %',
9090
'progress' => ' +0.09 %',
9191
],
92-
0.0001,
93-
0.001,
92+
0.01,
93+
0.1,
9494
];
9595

9696
yield 'not showable difference' => [
@@ -100,8 +100,8 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable
100100
'new' => ' 0.01 %',
101101
'progress' => ' +0.01 %',
102102
],
103-
0.00001,
104-
0.0001,
103+
0.001,
104+
0.01,
105105
];
106106
}
107107
}

tests/Unit/Reader/BaselineReaderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function getDataForTestPositiveFlow(): iterable
5959
{
6060
yield [
6161
[
62-
'methods' => 1,
63-
'conditionals' => 3,
64-
'statements' => 5,
65-
'elements' => 7,
66-
'coveredmethods' => 2,
67-
'coveredconditionals' => 4,
68-
'coveredstatements' => 6,
69-
'coveredelements' => 8,
62+
'methods' => 2,
63+
'conditionals' => 4,
64+
'statements' => 6,
65+
'elements' => 8,
66+
'coveredmethods' => 1,
67+
'coveredconditionals' => 3,
68+
'coveredstatements' => 5,
69+
'coveredelements' => 7,
7070
],
7171
__DIR__ . '/../../fixtures/baseline/baseline.json',
7272
];

tests/fixtures/baseline/baseline.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"methods": 1,
3-
"coveredmethods": 2,
4-
"conditionals": 3,
5-
"coveredconditionals": 4,
6-
"statements": 5,
7-
"coveredstatements": 6,
8-
"elements": 7,
9-
"coveredelements": 8
2+
"methods": 2,
3+
"coveredmethods": 1,
4+
"conditionals": 4,
5+
"coveredconditionals": 3,
6+
"statements": 6,
7+
"coveredstatements": 5,
8+
"elements": 8,
9+
"coveredelements": 7
1010
}

0 commit comments

Comments
 (0)