MDL-33075 find correct location of failed test case classes

This commit is contained in:
Petr Skoda 2012-05-17 18:36:46 +02:00
parent 4f7f2a8828
commit f32ecd2fbe

View file

@ -44,16 +44,28 @@ class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter {
$exception = $defect->thrownException();
$trace = $exception->getTrace();
$file = null;
if (class_exists('ReflectionClass')) {
$reflection = new ReflectionClass($testName);
$file = $reflection->getFileName();
} else {
$file = false;
$dirroot = realpath($CFG->dirroot).DIRECTORY_SEPARATOR;
$classpath = realpath("$CFG->dirroot/lib/phpunit/classes").DIRECTORY_SEPARATOR;
foreach ($trace as $item) {
if (strpos($item['file'], $dirroot) === 0 and strpos($item['file'], $classpath) !== 0) {
if ($content = file_get_contents($item['file'])) {
if (preg_match('/class\s+'.$testName.'\s+extends/', $content)) {
$file = $item['file'];
break;
}
}
if ($file === null) {
}
}
}
if ($file === false) {
return;
}