Skip to content

Instantly share code, notes, and snippets.

@scmrus
Last active December 9, 2021 19:38
Show Gist options
  • Save scmrus/ec4882d02f951bdbb783296f7da1a1c4 to your computer and use it in GitHub Desktop.
Save scmrus/ec4882d02f951bdbb783296f7da1a1c4 to your computer and use it in GitHub Desktop.
xdebug-code-coverage (global)
<?php
$_xdebug_code_coverage = new class {
private $coverage;
private $covFile;
public function __construct()
{
require_once __DIR__ . '/../vendor/autoload.php';
$uid = uniqid();
$this->covFile = "/tmp/xdebug-code-coverage/${uid}.cov";
$this->coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage;
$this->coverage->filter()->addDirectoryToWhitelist(__DIR__ . '/../app');
$this->coverage->filter()->addDirectoryToWhitelist(__DIR__ . '/../batch');
$this->coverage->start($uid);
}
public function __destruct()
{
$this->coverage->stop();
(new \SebastianBergmann\CodeCoverage\Report\PHP)->process($this->coverage, $this->covFile);
}
};
@scmrus
Copy link
Author

scmrus commented Dec 9, 2021

xdebug.ini:

[xdebug]
zend_extension = xdebug
xdebug.mode = coverage
auto_prepend_file = /var/www/tests/xdebug-coverage.php

@scmrus
Copy link
Author

scmrus commented Dec 9, 2021

to merge all data into one report:
./vendor/bin/phpcov merge --html ./coverage-report /tmp/xdebug-code-coverage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment