Recommend this page to a friend! |
Download |
Info | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2024-11-17 (3 days ago) | Not enough user ratings | Total: 16 This week: 2 | All time: 11,381 This week: 29 |
Version | License | PHP version | Categories | |||
phpunit-coverage-che 2.0.1 | MIT/X Consortium ... | 8.2.0 | Statistics, Console, Testing, PHP 8 |
Description | Author | |
This package can check code coverage using the clover XML report. |
It is recommended to use the phar version of this library, which can be found on the GitHub releases page.
It can also be installed via composer, with:
composer require --dev esi/phpunit-coverage-check:^2.0
View the included README.md file for more information.
PHPUnit Coverage Check - Check the code coverage using the clover report of PHPUnit.
This php script will read the clover xml report from PHPUnit and calculate the coverage score. Based on the given threshold the script will exit ok if the coverage is higher than the threshold or exit with code 1 if the coverage is lower than the threshold.
This script can be used in your continuous deployment environment or for example added to a pre-commit hook.
A GitHub action has been created for this library and can be found in the PHPUnit Coverage Check Action repository, or on the GitHub Marketplace.
This library is a fork of/based upon rregeer/phpunit-coverage-check by Richard Regeer.
Most of this library has been rewritten from the ground up, to replace and improve a majority of the original library. The overall idea, and key pieces of the calculation, are thanks to the original library. Many thanks and much appreciation to Richard Regeer for his wonderful work.
Please see License and the LICENSE file for more information.
For more information on changes made in this library, in comparison to the original by Richard Regeer, please see the CHANGELOG file.
Phar generation is handled by using Box. My implementation of the coverage:check
command, with Symfony\Console, was inspired by SensioLabs Security Checker.
This project is not in any way an official `PHPUnit
project. Meaning, that it is not associated with, or endorsed by, the
PHPUnit
project or its author
Sebastian Bergmann
`.
The script can be installed using composer. Add this repository as a dependency to the composer.json file.
$ composer require --dev esi/phpunit-coverage-check:^2.0
To use PHPUnit Coverage Check on PHP 8.1, use version 1.0.0 (and check 1.x's readme as usage is slightly different):
$ composer require --dev esi/phpunit-coverage-check:^1.0
Download the phpunit-coverage-check.phar
from an available release. It is recommended to check the signature when downloading the Phar from a GitHub Release (with phpunit-coverage-check.phar.asc
).
# Adjust the URL based on the latest release
wget -O phpunit-coverage-check.phar "https://github.com/ericsizemore/phpunit-coverage-check/releases/download/2.0.0/phpunit-coverage-check.phar"
wget -O phpunit-coverage-check.phar.asc "https://github.com/ericsizemore/phpunit-coverage-check/releases/download/2.0.0/phpunit-coverage-check.phar.asc"
# Check that the signature matches
gpg --verify phpunit-coverage-check.phar.asc phpunit-coverage-check.phar
# Check the issuer (the ID can also be found from the previous command)
gpg --keyserver hkps://keys.openpgp.org --recv-keys F8367C6E9D7A7028292144AAC9D8B66FF3C06696
rm phpunit-coverage-check.phar.asc
chmod +x phpunit-coverage-check.phar
The Phar files of PHPUnit Coverage Check are signed with a public key associated to `admin@secondversion.com.
`.
The key(s) associated with this E-Mail address
can be queried at keys.openpgp.org
.
You can also install the PHPUnit Coverage Check Phar with Phive
.
If not already using Phive, you can read more about it here, also Phive installation and usage.
The script has 2 parameters that are mandatory to return the code coverage.
Generate the clover.xml
file by using PHPUnit:
$ php vendor/bin/phpunit --coverage-clover clover.xml
It's also possible to add the coverage report generation to your PHPUnit configuration file (phpunit.xml.dist
for example). You would add to following lines to the xml file inside the <coverage>
tag:
<report>
<clover outputFile="clover.xml"/>
</report>
$ php vendor/bin/coverage-check /path/to/clover.xml 100
$ php vendor/bin/coverage-check /path/to/clover.xml 100 --only-percentage
# -O for only-percentage works as well
$ php vendor/bin/coverage-check /path/to/clover.xml 100 -O
# -F or show-files will display coverage per file, formatted in a table
$ php vendor/bin/coverage-check /path/to/clover.xml 100 -F
You can also use the Api directly if you wish. I created a function called nonConsoleCall
that will process and return the data, similar to how the console application displays it.
/
* Processes the coverage data with the given clover file and threshold, and returns the information
* similar to how the Console application will.
*
* This is mainly useful for those that may wish to use this library outside the CLI/Console or PHAR.
*/
public function nonConsoleCall(string $cloverFile, int $threshold = 100, bool $onlyPercentage = false): string
An example usage:
use Esi\CoverageCheck\CoverageCheck;
$check = new CoverageCheck();
$results = $check->nonConsoleCall(__DIR__ . '/tests/fixtures/clover.xml', 90);
echo $results; // Total code coverage is 90.32%
$ php phpunit-coverage-check.phar /path/to/clover.xml 100
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 --only-percentage
# -O for only-percentage works as well
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 -O
# -F or show-files will display coverage per file, formatted in a table
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 -F
With --only-percentage
(or -O
) enabled, the CLI command will only return the resulting coverage percentage.
With --show-files
(or -F
), --only-percentage
will be ignored. This option parses the clover file for coverage information for each file in the project/package, determine coverage, and display the information in a table. For example:
$ php coverage-check build/logs/clover.xml 90 -F
------------------------------------------------------------------- -------------------------- ----------
File Elements (Covered/Total) Coverage
------------------------------------------------------------------- -------------------------- ----------
[...]\phpunit-coverage-check\src\Application.php 12/12 100.00%
[...]\phpunit-coverage-check\src\Command\CoverageCheckCommand.php 94/94 100.00%
[...]\phpunit-coverage-check\src\CoverageCheck.php 80/80 100.00%
[...]\phpunit-coverage-check\src\Style\CoverageCheckStyle.php 12/12 100.00%
[...]\phpunit-coverage-check\src\Utils.php 39/39 100.00%
------------------------------------------------------------------- -------------------------- ----------
Overall Totals 237/237 100.00%
------------------------------------------------------------------- -------------------------- ----------
$ php coverage-check tests/fixtures/clover.xml 90 -F
----------------------------- -------------------------- ----------
File Elements (Covered/Total) Coverage
----------------------------- -------------------------- ----------
/tmp/Example/String.php 36/38 94.74%
/tmp/Example/StringList.php 20/24 83.33%
----------------------------- -------------------------- ----------
Overall Totals 56/62 89.04%
----------------------------- -------------------------- ----------
Bugs and feature requests are tracked on GitHub
Issues are the quickest way to report a bug. If you find a bug or documentation error, please check the following first:
See CONTRIBUTING
Eric Sizemore - <admin@secondversion.com> - <https://www.secondversion.com>
PHPUnit Coverage Check is licensed under the MIT License.
Files (41) |
File | Role | Description | ||
---|---|---|---|---|
.github (3 files, 2 directories) | ||||
src (3 files, 2 directories) | ||||
tests (2 directories) | ||||
.php-cs-fixer.dist.php | Example | Example script | ||
.scrutinizer.yml | Data | Auxiliary data | ||
backward-compatibility.md | Data | Auxiliary data | ||
box.json | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
CODE_OF_CONDUCT.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
CONTRIBUTING.md | Data | Auxiliary data | ||
coverage-check | Example | Example script | ||
LICENSE | Lic. | License text | ||
phpstan-baseline.neon | Data | Auxiliary data | ||
phpstan.neon | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
renovate.json | Data | Auxiliary data | ||
scoper.inc.php | Aux. | Configuration script | ||
SECURITY.md | Data | Auxiliary data |
Files (41) | / | .github |
File | Role | Description | ||
---|---|---|---|---|
ISSUE_TEMPLATE (3 files) | ||||
workflows (3 files) | ||||
dependabot.yml | Data | Auxiliary data | ||
FUNDING.yml | Data | Auxiliary data | ||
pull_request_template.md | Data | Auxiliary data |
Files (41) | / | .github | / | ISSUE_TEMPLATE |
File | Role | Description |
---|---|---|
1-bug_report.yml | Data | Auxiliary data |
2-feature_request.yml | Data | Auxiliary data |
config.yml | Data | Auxiliary data |
Files (41) | / | .github | / | workflows |
File | Role | Description |
---|---|---|
continuous-integration.yml | Data | Auxiliary data |
merge-me.yml | Data | Auxiliary data |
release.yml | Data | Auxiliary data |
Files (41) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Command (1 file) | ||||
Style (1 file) | ||||
Application.php | Class | Class source | ||
CoverageCheck.php | Class | Class source | ||
Utils.php | Class | Class source |
Files (41) | / | tests | / | fixtures |
File | Role | Description |
---|---|---|
clover.xml | Data | Auxiliary data |
empty.xml | Data | Auxiliary data |
invalid_root_element.xml | Data | Auxiliary data |
invalid_xml.xml | Data | Auxiliary data |
no_children.xml | Data | Auxiliary data |
no_project_metrics.xml | Data | Auxiliary data |
self_clover.xml | Data | Auxiliary data |
Files (41) | / | tests | / | src |
File | Role | Description | ||
---|---|---|---|---|
Command (1 file) | ||||
CoverageCheckTest.php | Class | Class source |
Files (41) | / | tests | / | src | / | Command |
File | Role | Description |
---|---|---|
CoverageCheckCommandTest.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.