2017 © Pedro Peláez
 

library live-code-coverage

image

matthiasnoback/live-code-coverage

  • Monday, April 2, 2018
  • by matthiasnoback
  • Repository
  • 6 Watchers
  • 76 Stars
  • 10,764 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 5 Versions
  • 34 % Grown

The README.md

Live code coverage

Build Status, (*1)

This library should help you generate code coverage reports on a live server (it doesn't have to be a production server of course)., (*2)

Install this library using:, (*3)

composer require matthiasnoback/live-code-coverage

Collecting code coverage data

In your front controller (e.g. index.php), add the following:, (*4)

` section will be used to configure the code coverage whitelist. For example, this `phpunit.xml.dist` file might look something like this:

```xml

<phpunit>
    <filter>
        <whitelist>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>

Most configuration directives that are available in PHPUnit work for this library too. If you notice that something doesn't work, please submit an issue., (*5)

If you don't provide a PHPUnit configuration file, no filters will be applied, so you will get a coverage report for all the code in your project, including vendor and test code if applicable., (*6)

If your application is a legacy application which exit()s or die()s before execution reaches the end of your front controller, the bootstrap should be slightly different:, (*7)

$shutDownCodeCoverage = LiveCodeCoverage::bootstrap(
    // ...
);
register_shutdown_function($shutDownCodeCoverage);

// Run your web application now...

Generating code coverage reports (HTML, Clover, etc.)

To merge all the coverage data and generate a report for it, install Sebastian Bergmann's phpcov tool. Run it like this (or in any other way you like):, (*8)

phpcov merge --html=./coverage/html ./var/coverage

Downsides

Please note that collecting code coverage data will make your application run much slower. Just see for yourself if that's acceptable., (*9)

The Versions