Skip to content

Commit 21310e5

Browse files
author
Fabrice Bernhard
committed
[PATCH] By-pass a code-coverage bug in XDebug
http://bugs.xdebug.org/bug_view_page.php?bug_id=0000331
1 parent 8965b12 commit 21310e5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

PHP/CodeCoverage/Driver/Xdebug.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,41 @@ public function stop()
9292
{
9393
$codeCoverage = xdebug_get_code_coverage();
9494
xdebug_stop_code_coverage();
95+
$codeCoverage = self::cleanFilenames($codeCoverage);
9596

9697
return $codeCoverage;
9798
}
99+
100+
/**
101+
* By-pass http://bugs.xdebug.org/bug_view_page.php?bug_id=0000331
102+
*
103+
* This Xdebug bug causes some filenames to be corrupted in the form
104+
* "[..]/wrongreturn.php(19) : assert code"
105+
* instead of
106+
* "[..]/wrongreturn.php"
107+
* The goal of this function is to by-pass the bug until it is fixed in Xdebug
108+
* by cleaning corrupted filenames
109+
*
110+
* @return array
111+
*/
112+
protected static function cleanFilenames($data)
113+
{
114+
foreach ($data as $file => $lines) {
115+
// check the existence of the wrong pattern in filename
116+
$correct_file = preg_replace('/\(\d+\) :.+/', '', $file);
117+
if ($file != $correct_file) {
118+
// if wrong filename found, we merge code coverage data
119+
// with correct filename
120+
if (!array_key_exists($correct_file, $data)) {
121+
$data[$correct_file] = array();
122+
}
123+
$data[$correct_file] += $lines;
124+
ksort($data[$correct_file]);
125+
// and unset wrong filename data
126+
unset($data[$file]);
127+
}
128+
}
129+
130+
return $data;
131+
}
98132
}

0 commit comments

Comments
 (0)