vitalyspirin / codecoverage
Creating code coverage reports (html) by using xdebug
Installs: 49
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2025-01-04 21:19:30 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(); });