コード例 #1
0
ファイル: hint_resultprinter.php プロジェクト: nigeli/moodle
 protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
 {
     global $CFG;
     parent::printDefectTrace($defect);
     $failedTest = $defect->failedTest();
     $testName = get_class($failedTest);
     $exception = $defect->thrownException();
     $trace = $exception->getTrace();
     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 === false) {
         return;
     }
     $cwd = getcwd();
     if (strpos($file, $cwd) === 0) {
         $file = substr($file, strlen($cwd) + 1);
     }
     $executable = 'phpunit';
     if (phpunit_bootstrap_is_cygwin()) {
         $file = str_replace('\\', '/', $file);
         $executable = 'phpunit.bat';
     }
     $this->write("\nTo re-run:\n {$executable} {$testName} {$file}\n");
 }
コード例 #2
0
ファイル: bootstraplib.php プロジェクト: JP-Git/moodle
/**
 * Returns relative path against current working directory,
 * to be used for shell execution hints.
 * @param string $moodlepath starting with "/", ex: "/admin/tool/cli/init.php"
 * @return string path relative to current directory or absolute path
 */
function phpunit_bootstrap_cli_argument_path($moodlepath)
{
    global $CFG;
    if (isset($CFG->admin) and $CFG->admin !== 'admin') {
        $moodlepath = preg_replace('|^/admin/|', "/{$CFG->admin}/", $moodlepath);
    }
    $cwd = getcwd();
    if (substr($cwd, -1) !== DIRECTORY_SEPARATOR) {
        $cwd .= DIRECTORY_SEPARATOR;
    }
    $path = realpath($CFG->dirroot . $moodlepath);
    if (strpos($path, $cwd) === 0) {
        $path = substr($path, strlen($cwd));
    }
    if (phpunit_bootstrap_is_cygwin()) {
        $path = str_replace('\\', '/', $path);
    }
    return $path;
}
コード例 #3
0
 protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
 {
     global $CFG;
     parent::printDefectTrace($defect);
     $failedTest = $defect->failedTest();
     $testName = get_class($failedTest);
     $exception = $defect->thrownException();
     $trace = $exception->getTrace();
     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 === false) {
         return;
     }
     $cwd = getcwd();
     if (strpos($file, $cwd) === 0) {
         $file = substr($file, strlen($cwd) + 1);
     }
     $executable = null;
     if (isset($_SERVER['argv'][0])) {
         if (preg_match('/phpunit(\\.bat|\\.cmd)?$/', $_SERVER['argv'][0])) {
             $executable = $_SERVER['argv'][0];
             for ($i = 1; $i < count($_SERVER['argv']); $i++) {
                 if (!isset($_SERVER['argv'][$i])) {
                     break;
                 }
                 if (in_array($_SERVER['argv'][$i], array('--colors', '--verbose', '-v', '--debug', '--strict'))) {
                     $executable .= ' ' . $_SERVER['argv'][$i];
                 }
             }
         }
     }
     if (!$executable) {
         $executable = 'phpunit';
         if (phpunit_bootstrap_is_cygwin()) {
             $file = str_replace('\\', '/', $file);
             $executable = 'phpunit.bat';
         }
     }
     $this->write("\nTo re-run:\n {$executable} {$testName} {$file}\n");
 }