Created
February 28, 2020 10:32
-
-
Save barryosull/8602dfb8daf45fab4f359d1b6bf4464d to your computer and use it in GitHub Desktop.
PHPUnit Code Coverage Report of Web App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
How to run a code coverage report on a web page: | |
Simply put this code after the vendor require and before the rest of the calling logic. | |
(Assumes you have PHPUnit installed) | |
**/ | |
require_once __DIR__ . "/../vendor/autoload.php"; | |
$coverage = new PHP_CodeCoverage(); | |
$coverage->filter()->addDirectoryToWhitelist('/path/to/code'); | |
$coverage->start('Test'); | |
// Generate the report even if `exit` is called | |
register_shutdown_function(function() use ($coverage){ | |
$coverage->stop(); | |
$writer = new PHP_CodeCoverage_Report_HTML; | |
$writer->process($coverage, '/tmp/code-coverage-report'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment