printDefectTrace() защищенный Метод

protected printDefectTrace ( PHPUnit_Framework_TestFailure $defect )
$defect PHPUnit_Framework_TestFailure
Пример #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");
 }
 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 (testing_is_cygwin()) {
             $file = str_replace('\\', '/', $file);
             if (!testing_is_mingw()) {
                 $executable = 'phpunit.bat';
             }
         }
     }
     $this->write("\nTo re-run:\n {$executable} {$testName} {$file}\n");
 }
Пример #3
0
 protected function printDefectTrace(\PHPUnit_Framework_TestFailure $defect)
 {
     $e = $defect->thrownException();
     if (!$e instanceof \atk4\core\PHPUnit_AgileExceptionWrapper) {
         return parent::printDefectTrace($defect);
     }
     $this->write((string) $e);
     $p = $e->getPrevious();
     if ($p instanceof \atk4\core\Exception or $p instanceof \atk4\dsql\Exception) {
         $this->write($p->getColorfulText());
     }
 }
Пример #4
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);
         $file = testing_cli_fix_directory_separator($file);
     }
     $pathprefix = testing_cli_argument_path('/');
     if ($pathprefix) {
         $pathprefix .= DIRECTORY_SEPARATOR;
     }
     // There is only vendor/bin/phpunit executable. There is no .cmd or .bat files.
     $executable = $pathprefix . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'phpunit';
     $executable = testing_cli_fix_directory_separator($executable);
     // Add server arguments to the rerun if passed.
     if (isset($_SERVER['argv'][0])) {
         if (preg_match('/phpunit(\\.bat|\\.cmd)?$/', $_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'))) {
                     $executable .= ' ' . $_SERVER['argv'][$i];
                 } else {
                     if (in_array($_SERVER['argv'][$i], array('-c', '--config'))) {
                         $executable .= ' ' . $_SERVER['argv'][$i] . ' ' . $_SERVER['argv'][++$i];
                     } else {
                         if (strpos($_SERVER['argv'][$i], '--config') === 0) {
                             $executable .= ' ' . $_SERVER['argv'][$i];
                         }
                     }
                 }
             }
         }
     }
     $this->write("\nTo re-run:\n {$executable} {$testName} {$file}\n");
 }
Пример #5
0
 /**
  * @param  PHPUnit_Framework_TestFailure $defect
  */
 protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
 {
     if (version_compare(PHPUnit_Runner_Version::id(), '3.6.0', '<')) {
         parent::printDefectTrace($defect);
     } else {
         // In PHPUnit 3.6, we need to filter the test harness files from the
         // stack trace ourselves. There is no way to access and customize the
         // built-in filter, as there used to be in PHP 3.5.
         //
         // (Actually, the built-in filter can be manipulated - see StackOverflow
         // http://goo.gl/HP2el. But it doesn't work with PHP 5.2.)
         ob_start();
         parent::printDefectTrace($defect);
         $trace = ob_get_clean();
         $lines = explode("\n", $trace);
         $filtered_stacktrace = array();
         foreach ($lines as $line) {
             $include = true;
             foreach ($this->blacklist as $blacklisted) {
                 $include = stripos($line, $blacklisted) !== 0;
                 if (!$include) {
                     break;
                 }
             }
             if ($include) {
                 $filtered_stacktrace[] = $line;
             }
         }
         $this->write(implode("\n", $filtered_stacktrace));
     }
 }