Download the PHP package league/phpunit-coverage-listener without Composer
On this page you can find all versions of the php package league/phpunit-coverage-listener. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download league/phpunit-coverage-listener
More information about league/phpunit-coverage-listener
Files in league/phpunit-coverage-listener
Package phpunit-coverage-listener
Short Description Utility library that allow you to process the PHPUnit code-coverage information and send it into some remote location via cURL
License MIT
Homepage https://github.com/php-loep/phpunit-coverage-listener
Informations about the package phpunit-coverage-listener
PHPUnit Coverage Listener
PHPUnit Coverage Listener is a utility library that allow you to process the PHPUnit code-coverage information and send it into some remote location via cURL.
The main goal of the PHPunit Coverage Listener package is to provide a mechanism that generate a payload data (from PHPUnit code-coverage information) named coverage.json
and send it to remote location, with bellow structure (simplified) :
Then in the target server, you could accept the payload as follow (simplified) :
Above json data could be process furthermore to expose usefull information about your code-coverage information in a way that fit with your specific needs. Coveralls service would be a perfect example in this scenario.
Requirement
- PHP >= 5.3.3
Install
Via Composer
Basic Usage
Let's say you want to send a payload data for Coveralls each time your Travis job successfully build. All you need to do is adding bellow section within your phpunit configuration that used by .travis.yml
(mostly you wont need this in your development environment) :
And thats it.
Advance Usage
As you may noticed on previous section, in order to work properly, Listener class need to know several things. They are being passed from your phpunit configuration within listener arguments directive.
Bellow table describe each configuration options respectively :
Key Name | Value | Description |
---|---|---|
printer |
League\PHPUnitCoverageListener\PrinterInterface |
Required |
hook |
League\PHPUnitCoverageListener\HookInterface |
Optional |
namespace |
String |
Optional |
repo_token |
String |
Required |
target_url |
String |
Required |
coverage_dir |
String |
Required |
send |
bool |
Optional |
printer
This option contains PrinterInterface
that will be used by Listener class in several points. In previous section, we set it to use StdOut
printer that will print out any output informations directly into standard output. You could use your own printer class as long as it implements required interface.
hook
This option allow you to hook into Listener life-cycle. HookInterface
has two method to be implemented : beforeCollect
and afterCollect
. It will receive Collection
data, and then will alter or do something with the data on each hook point. In the previous example, Travis
hook actually only contains bellow code :
Currently there are Travis
and Circle
hooks. You could register your own hook class that suit for your need as long as it implements required interface.
namespace
Option namespace
string could be passed into the Listener, so that the generated coverage information use "relative" name instead literal file path. For example, if your source is src/My/Package/Resource.php
, and you passing My\Package
as namespace option, generated file name within coverage payload data will be My/Package/Resource.php
.
repo_token
This option could be anything. Timestamp? Coveralls account token? Jenkins build token? Its up to you. But it was still neccessary to supply this option into the Listener class.
target_url
This option could be any valid url. For example, if you use Coveralls this option can be set to its REST endpoint : https://coveralls.io/api/v1/jobs
.
coverage_dir
The directory you specified here must be the same directory from which PHPUnit generate coverage.xml
report. Listener will also outputing coverage.json
within this directory, so ensure this directory is writable.
send
As default, this library purpose is to collect and generate code-coverage data then send those payload data into remote location. But if you want to only collect and generate the data, add bellow option :
within the listener arguments array directive.
Changelog
Contributing
Please see CONTRIBUTING for details.
Support
Bugs and feature request are tracked on GitHub
License
PHPUnit Coverage Listener is released under the MIT License. See the bundled LICENSE file for details.