From f32ecd2fbeeabc9af3e6d5661cdda5e7112e0313 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Thu, 17 May 2012 18:36:46 +0200 Subject: [PATCH] MDL-33075 find correct location of failed test case classes --- lib/phpunit/classes/hint_resultprinter.php | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/phpunit/classes/hint_resultprinter.php b/lib/phpunit/classes/hint_resultprinter.php index 02a09f8e222..638b4d0b112 100644 --- a/lib/phpunit/classes/hint_resultprinter.php +++ b/lib/phpunit/classes/hint_resultprinter.php @@ -44,16 +44,28 @@ class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter { $exception = $defect->thrownException(); $trace = $exception->getTrace(); - $file = null; - $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) { - $file = $item['file']; - break; + + 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; }