예제 #1
0
 protected static function printer($return_html)
 {
     $exception_output = '';
     $main_output = '';
     $failing_methods_output = '';
     if ($return_html) {
         $main_output = '<table class="unit_tests"><tr class="header"><td>Class Name</td><td>Passed</td><td>Failed</td><td>Exceptions</td></tr>';
         foreach (self::$classes as $class_name) {
             $main_output .= '<tr class="' . (self::$fails[$class_name] > 0 || count(self::$exceptions[$class_name]) || 0 ? 'fail' : 'pass') . '"><td class="class_name">' . $class_name . '</td><td>' . self::$passes[$class_name] . '</td><td>' . self::$fails[$class_name] . '</td><td>' . count(self::$exceptions[$class_name]) . '</td></tr>';
             foreach (self::$exceptions[$class_name] as $method_name => $exception) {
                 $exception_output .= '<h2>' . $class_name . '::' . $method_name . ' threw this exception:</h2><hr/>' . PicoraSupport::exceptionHandler($exception, true) . '<hr/>';
             }
         }
         $main_output .= '</table>';
         foreach (self::$failing_methods as $class_name => $fail_info) {
             foreach ($fail_info as $method_name => $fails) {
                 foreach ($fails as $item) {
                     $failing_methods_output .= '<li>' . $class_name . '::' . $method_name . ' ' . $item['method'] . ' failed on line ' . $item['line'] . ' in file ' . $item['file'] . '</li>';
                 }
             }
         }
         if ($failing_methods_output != '') {
             $failing_methods_output = '<ul>' . $failing_methods_output . '</ul>';
         }
     } else {
         $main_output = 'PicoraTest::run()' . chr(10);
         foreach (self::$classes as $class_name) {
             $main_output .= chr(9) . $class_name . ' ' . self::$fails[$class_name] . ' passed, ' . self::$fails[$class_name] . ' failed, ' . count(self::$exceptions[$class_name]) . ' exceptions.' . chr(10);
             foreach (self::$exceptions[$class_name] as $method_name => $exception) {
                 $exception_output .= $class_name . '::' . $method_name . ' threw this exception:' . chr(10) . picora_exception_handler($exception, true, false) . chr(10) . chr(10);
             }
             foreach (self::$failing_methods[$class_name] as $method_name => $fails) {
                 foreach ($fails as $info) {
                     $failing_methods_output .= ' - ' . $class_name . '::' . $method_name . ' ' . $info['method'] . ' failed on line ' . $info['line'] . ' in file ' . $info['file'] . chr(10);
                 }
             }
         }
     }
     return $main_output . $failing_methods_output . $exception_output;
 }
예제 #2
0
 public function __toString()
 {
     try {
         return $this->display();
     } catch (Exception $e) {
         PicoraSupport::exceptionHandler($e);
         exit;
     }
 }