diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46d3826..438a34b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,28 +37,17 @@ jobs: - uses: actions/checkout@v3 - - name: Set versions - run: | - sed -i 's/\^3.4|\^4.0|\^5.0|\^6.0/${{ matrix.symfony-version }}/g' composer.json - sed -i 's/\^7.5|\^9.5/${{ matrix.phpunit-version }}/g' composer.json - - name: Validate composer.json and composer.lock run: composer validate --strict - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- + - name: Set versions + run: composer run-script set_versions ${{ matrix.symfony-version }} ${{ matrix.phpunit-version }} - name: Install dependencies uses: ramsey/composer-install@v2 - name: Run test suite - run: composer run-script test + run: composer run-script phpunit phpstan: runs-on: ubuntu-latest @@ -69,17 +58,8 @@ jobs: - uses: actions/checkout@v3 - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - name: Install dependencies uses: ramsey/composer-install@v2 - name: PHPStan analyse - run: vendor/bin/phpstan analyse + run: composer run-script phpstan-analise diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5cfb08e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,46 @@ +CHANGELOG +========= + +2.0.1 +----- +* Bug fixes: + * Fix comparing and displaying of data used for comparing of Clover code coverage report with its baseline. +* Minors: + * Configure matrix for better dependencies testing. + * Update scripts in composer config and running of them on GitGub Actions. + * Added script to replace required versions of packages. + +2.0.0 +----- +* Feature: + * Changed format of Clover code coverage baseline to improve its readability. + * Added support for old version of Clover code coverage baseline. +* Backward compatibility breaks: + * Used package `symfony/console` instead of custom console calls handling. +* Deprecations: + * Scripts `bin/pccb_clover_build_baseline` and `bin/pccb_clover_compare` are deprecated. + Single script `bin/pccb` should be used for all commands calls. +* Minors: + * Configured Docker for dev purposes. + +1.1.0 +----- +* Features: + * Beautified report of clover baseline comparing results when used option "verbose". + * Added compatibility with PHP 7.1. +* Minors: + * Added check by PHPStan. + +1.0.0 +----- +* Features: + * Implemented baseline builder. +* Minors: + * Code refactored in OOP approach. + * Removed messages about fallback to the default options values. + * Configured running of automated tests on GitHub. + +0.1 +--- +* Features: + * Initial implementation of baseline comparing. diff --git a/bin/dev/set_composer_versions b/bin/dev/set_composer_versions new file mode 100644 index 0000000..4bdf346 --- /dev/null +++ b/bin/dev/set_composer_versions @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +SYMFONY_NEW_VERSION=$1 +PHPUNIT_NEW_VERSION=$2 + +sed -i "s/\^3.4|\^4.0|\^5.0|\^6.0/${SYMFONY_NEW_VERSION}/g" composer.json +sed -i "s/\^7.5|\^9.5/${PHPUNIT_NEW_VERSION}/g" composer.json diff --git a/composer.json b/composer.json index 205a4c5..e6bbd65 100644 --- a/composer.json +++ b/composer.json @@ -44,8 +44,14 @@ "phpunit/phpunit": "^7.5|^9.5" }, "scripts": { - "test": "vendor/bin/phpunit", - "phpstan-analise": "vendor/bin/phpstan analyse" + "test": [ + "@phpunit", + "@phpstan-analise" + ], + "phpunit": "vendor/bin/phpunit", + "phpstan-analise": "vendor/bin/phpstan analyse", + "phpstan-update": "vendor/bin/phpstan analyse --generate-baseline phpstan-baseline.neon", + "set_versions": "sh bin/dev/set_composer_versions" }, "suggest": { "phpunit/phpunit": "PHPUnit must be used to generate code coverage report." diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fd09b69..72b34d4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15,11 +15,21 @@ parameters: count: 2 path: tests/Unit/ComparatorTest.php + - + message: "#^Trying to mock an undefined method read\\(\\) on class \\.$#" + count: 2 + path: tests/Unit/ComparatorTest.php + - message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#" count: 1 path: tests/Unit/Model/ConsoleTableTest.php + - + message: "#^Trying to mock an undefined method getValues\\(\\) on class \\.$#" + count: 1 + path: tests/Unit/Model/ConsoleTableTest.php + - message: "#^Expression \"\\$coverage\\['any_key'\\]\" on a separate line does not do anything\\.$#" count: 2 diff --git a/src/Model/ComparingRow.php b/src/Model/ComparingRow.php index 0dded02..0f93b44 100644 --- a/src/Model/ComparingRow.php +++ b/src/Model/ComparingRow.php @@ -29,8 +29,8 @@ final class ComparingRow public function __construct(string $name, float $old, float $new) { $this->name = $name; - $this->old = round($old * 100, 2); - $this->new = round($new * 100, 2); + $this->old = round($old, 2); + $this->new = round($new, 2); $this->progress = $this->new - $this->old; } @@ -58,9 +58,14 @@ public function getValues(): array return [ 'name' => $this->name, - 'old' => str_pad(number_format($this->old, 2), 6, ' ', \STR_PAD_LEFT) . ' %', - 'new' => str_pad(number_format($this->new, 2), 6, ' ', \STR_PAD_LEFT) . ' %', - 'progress' => str_pad($progressPrefix . number_format($this->progress, 2), 7, ' ', \STR_PAD_LEFT) . ' %', + 'old' => $this->formatPercentage($this->old, 6), + 'new' => $this->formatPercentage($this->new, 6), + 'progress' => $this->formatPercentage($this->progress, 7, $progressPrefix), ]; } + + private function formatPercentage(float $value, int $length, string $prefix = ''): string + { + return str_pad($prefix . number_format($value, 2, '.', ''), $length, ' ', \STR_PAD_LEFT) . ' %'; + } } diff --git a/tests/Functional/Command/CloverCompareCommandTest.php b/tests/Functional/Command/CloverCompareCommandTest.php new file mode 100644 index 0000000..60946b3 --- /dev/null +++ b/tests/Functional/Command/CloverCompareCommandTest.php @@ -0,0 +1,35 @@ + 'methods', + 'old' => ' 1.00 %', + 'new' => ' 50.00 %', + 'progress' => ' +49.00 %', + ], + [ + 'name' => 'conditionals', + 'old' => ' 30.00 %', + 'new' => ' 75.00 %', + 'progress' => ' +45.00 %', + ], + [ + 'name' => 'statements', + 'old' => ' 50.00 %', + 'new' => ' 83.33 %', + 'progress' => ' +33.33 %', + ], + [ + 'name' => 'elements', + 'old' => ' 70.00 %', + 'new' => ' 87.50 %', + 'progress' => ' +17.50 %', + ], + ]; + $baselinePath = __DIR__ . '/../fixtures/baseline/baseline_v2.json'; + $baselineReader = (new BaselineReaderFactory())->createReader($baselinePath); + $cloverPath = __DIR__ . '/../fixtures/clover/clover.xml'; + $cloverReader = new CloverReader($cloverPath); + $results = (new Comparator($baselineReader, $cloverReader))->compare(); + $actual = array_map(static function (ComparingRow $row): array { + return $row->getValues(); + }, $results->getRows()); + + self::assertEquals($expected, $actual); + } +} diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php new file mode 100644 index 0000000..376fbbc --- /dev/null +++ b/tests/Integration/IntegrationTestCase.php @@ -0,0 +1,12 @@ + [ [ 'name' => 'any string', - 'old' => ' 10.00 %', - 'new' => ' 10.00 %', + 'old' => ' 0.10 %', + 'new' => ' 0.10 %', 'progress' => ' 0.00 %', ], 0.1, @@ -68,7 +68,7 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable 'progress' => '+100.00 %', ], 0.0, - 1.0, + 100.0, ]; yield '-100 %' => [ @@ -78,7 +78,7 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable 'new' => ' 0.00 %', 'progress' => '-100.00 %', ], - 1.0, + 100.0, 0.0, ]; @@ -89,8 +89,8 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable 'new' => ' 0.10 %', 'progress' => ' +0.09 %', ], - 0.0001, - 0.001, + 0.01, + 0.1, ]; yield 'not showable difference' => [ @@ -100,8 +100,8 @@ public function getDataForTestNumbersFormattingOnJsonSerialise(): iterable 'new' => ' 0.01 %', 'progress' => ' +0.01 %', ], - 0.00001, - 0.0001, + 0.001, + 0.01, ]; } } diff --git a/tests/Unit/Reader/BaselineReaderTest.php b/tests/Unit/Reader/BaselineReaderTest.php index a915393..c7eda1f 100644 --- a/tests/Unit/Reader/BaselineReaderTest.php +++ b/tests/Unit/Reader/BaselineReaderTest.php @@ -59,14 +59,14 @@ public function getDataForTestPositiveFlow(): iterable { yield [ [ - 'methods' => 1, - 'conditionals' => 3, - 'statements' => 5, - 'elements' => 7, - 'coveredmethods' => 2, - 'coveredconditionals' => 4, - 'coveredstatements' => 6, - 'coveredelements' => 8, + 'methods' => 2, + 'conditionals' => 4, + 'statements' => 6, + 'elements' => 8, + 'coveredmethods' => 1, + 'coveredconditionals' => 3, + 'coveredstatements' => 5, + 'coveredelements' => 7, ], __DIR__ . '/../../fixtures/baseline/baseline.json', ]; diff --git a/tests/fixtures/baseline/baseline.json b/tests/fixtures/baseline/baseline.json index 6b200a7..74cac03 100644 --- a/tests/fixtures/baseline/baseline.json +++ b/tests/fixtures/baseline/baseline.json @@ -1,10 +1,10 @@ { - "methods": 1, - "coveredmethods": 2, - "conditionals": 3, - "coveredconditionals": 4, - "statements": 5, - "coveredstatements": 6, - "elements": 7, - "coveredelements": 8 + "methods": 2, + "coveredmethods": 1, + "conditionals": 4, + "coveredconditionals": 3, + "statements": 6, + "coveredstatements": 5, + "elements": 8, + "coveredelements": 7 }