PHPUnit_TextUI_ResultPrinter::printDefectTrace PHP Méthode

printDefectTrace() protected méthode

protected printDefectTrace ( PHPUnit_Framework_TestFailure $defect )
$defect PHPUnit_Framework_TestFailure
    protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
    {
        $e = $defect->thrownException();
        $this->write((string) $e);
        while ($e = $e->getPrevious()) {
            $this->write("\nCaused by\n" . $e);
        }
    }

Usage Example

Exemple #1
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);
     }
     $this->write("\nTo re-run:\n phpunit {$testName} {$file}\n");
 }
All Usage Examples Of PHPUnit_TextUI_ResultPrinter::printDefectTrace