Skip to content

Instantly share code, notes, and snippets.

@barryosull
Created February 28, 2020 10:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryosull/8602dfb8daf45fab4f359d1b6bf4464d to your computer and use it in GitHub Desktop.
Save barryosull/8602dfb8daf45fab4f359d1b6bf4464d to your computer and use it in GitHub Desktop.
PHPUnit Code Coverage Report of Web App
<?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