CodeCoverage
Wrapper classes around xDebug to show code coverage data as html files., (*1)
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., (*2)
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)., (*3)
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):, (*4)
require_once(__DIR__ . '/vendor/vitalyspirin/codecoverage/src/CodeCoverage.php');
vitalyspirin\codecoverage\CodeCoverage::start(__DIR__ . '/codecoverage');
register_shutdown_function(function() {
vitalyspirin\codecoverage\CodeCoverage::stop();
});
Screenshot
, (*5)