vstelmakh / covelyzer
Tool to analyze PHPUnit test coverage report in clover format
Installs: 3 613
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.1 || ^8
- ext-dom: *
- ext-libxml: *
- symfony/console: ^3.2 || ^4 || ^5
Requires (Dev)
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^7.5.3 || ^8 || ^9
- squizlabs/php_codesniffer: ^3.5
Suggests
- phpunit/phpunit: Allows run tests and generate coverage report
This package is auto-updated.
Last update: 2024-11-16 03:12:08 UTC
README
Covelyzer - PHP console tool to analyze PHPUnit test coverage report in clover (XML) format. Covelyzer integrates coverage metrics directly into the workflow forcing developers to write tests and forbidding delivery of uncovered code.
Highlights:
- Works in console
- Easy to integrate
- Flexible configuration
- Same setup locally and on CI
- Not depend on third-party service
Installation
Install the latest version with Composer:
composer require --dev vstelmakh/covelyzer
Usage
Before you start, run tests with options to generate coverage report in XML format. See corresponding PHPUnit documentation reference Code coverage analysis and Covelyzer phpunit.xml, composer.json scripts section as an example.
Run tests with XML coverage xdebug example:
vendor/bin/phpunit --dump-xdebug-filter var/xdebug-filter.php && \
vendor/bin/phpunit --prepend var/xdebug-filter.php --coverage-clover var/coverage.xml --whitelist src
Run Covelyzer with default configuration:
vendor/bin/covelyzer var/coverage.xml
To specify additional configuration see Configuration.
Configuration
Configuration defined in covelyzer.xml
located under project root (where vendor dir located). Or
configuration path could be overridden via -c | --config
command option:
vendor/bin/covelyzer var/coverage.xml -c path/to/covelyzer.xml
If no configuration file provided - default configuration is used.
Example configuration:
<?xml version="1.0" encoding="UTF-8" ?> <covelyzer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/vstelmakh/covelyzer/resources/config.xsd" timezone="Europe/Berlin" > <project minCoverage="100"/> <class minCoverage="100"/> </covelyzer>
<covelyzer>
element
Config root element.
timezone
attribute
Timezone should be used to display timestamp.
- use:
optional
- type:
string
(see: php timezones) - command option: could be defined/overridden via
--timezone
command option
<project>
element
Defines configuration for project coverage report. If defined project coverage report will be rendered.
- parent:
<covelyzer>
- use:
optional
minCoverage
attribute
Minimum coverage value. If project have less coverage - report will fail.
- use:
required
- type:
float
(min: 0, max: 100)
<class>
element
Defines configuration for class coverage report. If defined class coverage report will be rendered.
- parent:
<covelyzer>
- use:
optional
minCoverage
attribute
Minimum coverage value. If any class have less coverage - report will fail.
- use:
required
- type:
float
(min: 0, max: 100)
Tips & tricks
Use help option
Use -h | --help
command option to display Covelyzer help data. It contains all available arguments, options and usage examples.
vendor/bin/covelyzer --help
Ignore code blocks
Covelyzer will analyze full report produced by PHPUnit. In some cases you want to ignore some code parts to not be taken into account. There are several options available, see Ignoring code blocks in PHPUnit documentation.
Speed up coverage with Xdebug
The performance of code coverage data collection with Xdebug can be improved by delegating whitelist filtering to Xdebug. See corresponding PHPUnit docs section: Speeding up code coverage with Xdebug.
Credits
Volodymyr Stelmakh
Licensed under the MIT License. See LICENSE for more information.