Skip to content

Commit

Permalink
CodeCoverage: support Xdebug 3 (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripudil authored and dg committed Dec 3, 2020
1 parent 10a9b57 commit 652853e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Runner/CliTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,15 @@ private function prepareCodeCoverage(Runner $runner): string
file_put_contents($this->options['--coverage'], '');
$file = realpath($this->options['--coverage']);

[$engine] = reset($engines);
[$engine, $version] = reset($engines);

$runner->setEnvironmentVariable(Environment::COVERAGE, $file);
$runner->setEnvironmentVariable(Environment::COVERAGE_ENGINE, $engine);

if ($engine === CodeCoverage\Collector::ENGINE_XDEBUG && version_compare($version, '3.0.0', '>=')) {
$runner->addPhpIniOption('xdebug.mode', ltrim(ini_get('xdebug.mode') . ',coverage', ','));
}

if ($engine === CodeCoverage\Collector::ENGINE_PCOV && count($this->options['--coverage-src'])) {
$runner->addPhpIniOption('pcov.directory', Helpers::findCommonDirectory($this->options['--coverage-src']));
}
Expand Down
9 changes: 8 additions & 1 deletion tests/CodeCoverage/Collector.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ $engines = array_filter(CodeCoverage\Collector::detectEngines(), function (array
if (count($engines) < 1) {
Tester\Environment::skip('Requires Xdebug or PHPDB SAPI.');
}
[$engine] = reset($engines);
[$engine, $version] = reset($engines);

if ($engine === CodeCoverage\Collector::ENGINE_XDEBUG
&& version_compare($version, '3.0.0', '>=')
&& strpos(ini_get('xdebug.mode'), 'coverage') === false
) {
Tester\Environment::skip('Requires xdebug.mode=coverage with Xdebug 3.');
}

if (CodeCoverage\Collector::isStarted()) {
Tester\Environment::skip('Requires running without --coverage.');
Expand Down

0 comments on commit 652853e

Please sign in to comment.