vitalyspirin/codecoverage

There is no license information available for the latest version (2.0.1) of this package.

Creating code coverage reports (html) by using xdebug

2.0.1 2016-07-12 18:12 UTC

This package is not auto-updated.

Last update: 2024-05-25 17:33:08 UTC


README

Wrapper classes around xDebug to show code coverage data as html files.

Installation

composer require vitalyspirin/codecoverage

To generate HTML reports and see them in a table you can put file examples/reporting.php on the same level as a directory for code coverage reports. Then in a browser navigate to reporting.php.

Inside directory for code coverage reports you can create file 'userstory' with the word "off" as a content to disable code coverage (and speed up execution).

Quick Start and Examples

use vitalyspirin\codecoverage\CodeCoverage;

$reportDir = 'CodeCoverageReports';  // directory for report files 
CodeCoverage::deleteAllReports($reportDir); // remove this if you need cumulative coverage
CodeCoverage::start();

$a = new A();

CodeCoverage::stop();
CodeCoverage::deleteTxtReports(); // remove this if you need cumulative coverage
CodeCoverage::$trackedFileList['test2'] = [];
CodeCoverage::$trackedFileList['test2'][] = realpath(dirname(__FILE__) . '/A.php');

$reportDir = 'CodeCoverageReports';  // directory for report files 
CodeCoverage::start($reportDir, "test2"); // "test2" is used to indicate which files should be analyzed.

$a = new A();

CodeCoverage::stop();

General way to put it into main router (index.php):

require_once(__DIR__ . '/vendor/vitalyspirin/codecoverage/src/CodeCoverage.php');

vitalyspirin\codecoverage\CodeCoverage::start(__DIR__ . '/codecoverage');

register_shutdown_function(function() {
    vitalyspirin\codecoverage\CodeCoverage::stop();
});

Screenshot

screenshot1.png