Skip to content

By-Pass Xdebug bug #331 by cleaning the filenames returned in the Xdebug.php driver #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions PHP/CodeCoverage/Driver/Xdebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,41 @@ public function stop()
{
$codeCoverage = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
$codeCoverage = self::cleanFilenames($codeCoverage);

return $codeCoverage;
}

/**
* By-pass http://bugs.xdebug.org/bug_view_page.php?bug_id=0000331
*
* This Xdebug bug causes some filenames to be corrupted in the form
* "[..]/wrongreturn.php(19) : assert code"
* instead of
* "[..]/wrongreturn.php"
* The goal of this function is to by-pass the bug until it is fixed in Xdebug
* by cleaning corrupted filenames
*
* @return array
*/
protected static function cleanFilenames($data)
{
foreach ($data as $file => $lines) {
// check the existence of the wrong pattern in filename
$correct_file = preg_replace('/\(\d+\) :.+/', '', $file);
if ($file != $correct_file) {
// if wrong filename found, we merge code coverage data
// with correct filename
if (!array_key_exists($correct_file, $data)) {
$data[$correct_file] = array();
}
$data[$correct_file] += $lines;
ksort($data[$correct_file]);
// and unset wrong filename data
unset($data[$file]);
}
}

return $data;
}
}
34 changes: 34 additions & 0 deletions Tests/PHP/CodeCoverage/Driver/XdebugTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Tests for the PHP_CodeCoverage_Driver_Xdebug class.
*
* @category PHP
* @package CodeCoverage_Driver
* @subpackage Tests
* @author Fabrice Bernhard <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-code-coverage
*/
class PHP_CodeCoverage_Driver_XdebugTest extends PHPUnit_Framework_TestCase
{
/**
* Tests that the Xdebug driver by-passed Xdebug bug #331
* http://bugs.xdebug.org/bug_view_page.php?bug_id=0000331
*
* @covers PHP_CodeCoverage_Driver_Xdebug::cleanFilenames
* @covers PHP_CodeCoverage_Driver_Xdebug::stop
*
*/
public function testCoveredFiles()
{
$driver = new PHP_CodeCoverage_Driver_Xdebug;
$driver->start();
assert('2 >= 0');
$data = $driver->stop();
foreach ($data as $file => $lines) {
$this->assertNotcontains(' : assert code', $file);
}
}
}