digitalrevolution / phpunit-file-coverage-inspection
Configurable phpunit file coverage inspection
Installs: 51 321
Dependents: 11
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 3
Requires
- php: >=8.1
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-xmlwriter: *
- symfony/console: ^6.2 || ^7.0
Requires (Dev)
- digitalrevolution/accessorpair-constraint: >= 2.1.7
- mikey179/vfsstream: ^1.6.7
- phpmd/phpmd: ^2.14
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.0 || ^11.2
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
README
PHPUnit coverage inspection
A tool to allow code coverage rules be defined per file. Set a minimum coverage threshold for every file and configure custom minimum coverage for existing files if the current test coverage is not up to standards yet. Inspection failure will be output in checkstyle format, allowing it to be imported in ci/cd tools.
Use case
Standard coverage calculation is calculated over the whole codebase. If for example the threshold is 80% and one file drops below 80% you never notice this because the overall coverage went from 87.6% to 87.4%. This package makes sure that that doesn't happen anymore and coverage is calculated on a per-file basis.
Supported formats
- Input: clover coverage.xml
- Output: checkstyle or gitlab
Installation
Include the library as dependency in your own project via:
composer require "digitalrevolution/phpunit-file-coverage-inspection" --dev
Configuration
File: phpfci.xml
<?xml version="1.0" encoding="UTF-8"?> <phpfci xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/digitalrevolution/phpunit-file-coverage-inspection/resources/phpfci.xsd" min-coverage="100" allow-uncovered-methods="false" > <custom-coverage> <!-- directory based coverage rule --> <directory path="src/Lib/" min="90"/> <!-- subdirectories will superceed a parent directory rule --> <directory path="src/Lib/Config/" min="100"/> <!-- file rule will always superceed a directory rule --> <file path="src/Lib/Config/File.php" min="80"/> </custom-coverage> <!-- when 'allow-uncovered-methods' is set to false, override this behaviour for specific files: --> <ignore-uncovered-methods> <file path="src/Command/ExampleCommand.php"/> </ignore-uncovered-methods> </phpfci>
or generate a config file based on existing coverage results
php vendor/bin/phpfci baseline --baseDir /home/ci/workspace coverage.xml ./phpfci.xml
The base directory will be subtracted from the filepaths in coverage.xml
Usage
Checkstyle format:
php vendor/bin/phpfci inspect coverage.xml --reportCheckstyle=reports/checkstyle.xml
Gitlab format:
php vendor/bin/phpfci inspect coverage.xml --reportGitlab=reports/gitlab.errors.json
Gitlab format to file and text output to stdout:
php vendor/bin/phpfci inspect coverage.xml --reportGitlab=reports/gitlab.errors.json --reportText
Text format to stdout:
php vendor/bin/phpfci inspect coverage.xml php vendor/bin/phpfci inspect coverage1.xml coverage2.xml
php vendor/bin/phpfci inspect coverage.xml --reportText
Command line arguments
Note: if no --reportGitlab
, --reportCheckstyle
or --reportText
is set, it will default to --reportText=php://stdout
Migrating from 1 to 2
The third required argument and --report
has been removed, and should be replaced by:
--reportGitlab=<file>
, --reportCheckstyle=<file>
or --reportText=<file>
About us
At 123inkt (Part of Digital Revolution B.V.), every day more than 50 development professionals are working on improving our internal ERP and our several shops. Do you want to join us? We are looking for developers.