Esempio n. 1
0
 public function onRun(RunEvent $e)
 {
     /* @var $test \ZFTool\Diagnostics\Test\TestInterface */
     $test = $e->getTarget();
     try {
         ErrorHandler::start($this->getCatchErrorSeverity());
         $result = $test->run();
         ErrorHandler::stop(true);
     } catch (ErrorException $e) {
         return new Failure('PHP ' . static::getSeverityDescription($e->getSeverity()) . ': ' . $e->getMessage(), $e);
     } catch (\Exception $e) {
         ErrorHandler::stop(false);
         return new Failure('Uncaught ' . get_class($e) . ': ' . $e->getMessage(), $e);
     }
     // Check if we've received a Result object
     if (is_object($result)) {
         if (!$result instanceof ResultInterface) {
             return new Failure('Test returned unknown object ' . get_class($result), $result);
         }
         return $result;
         // Interpret boolean as a failure or success
     } elseif (is_bool($result)) {
         if ($result) {
             return new Success();
         } else {
             return new Failure();
         }
         // Convert scalars to a warning
     } elseif (is_scalar($result)) {
         return new Warning('Test returned unexpected ' . gettype($result), $result);
         // Otherwise interpret as failure
     } else {
         return new Failure('Test returned unknown result of type ' . gettype($result), $result);
     }
 }
Esempio n. 2
0
 public function onAfterRun(RunEvent $e)
 {
     $test = $e->getTarget();
     $result = $e->getLastResult();
     $descr = ' ' . $test->getLabel();
     if ($message = $result->getMessage()) {
         $descr .= ': ' . $result->getMessage();
     }
     if ($this->displayData && ($data = $result->getData())) {
         $descr .= PHP_EOL . str_repeat('-', $this->width - 15);
         $data = $result->getData();
         if (is_object($data) && $data instanceof \Exception) {
             $descr .= PHP_EOL . get_class($data) . PHP_EOL . $data->getMessage() . $data->getTraceAsString();
         } else {
             $descr .= PHP_EOL . @var_export($result->getData(), true);
         }
         $descr .= PHP_EOL . str_repeat('-', $this->width - 15);
     }
     // Draw status line
     if ($result instanceof Success) {
         $this->console->write('       ');
         $this->console->write('  OK  ', Color::NORMAL, Color::GREEN);
         $this->console->writeLine($this->strColPad($descr, $this->width - 15, '              '), Color::GREEN);
     } elseif ($result instanceof Failure) {
         $this->console->write('       ');
         $this->console->write(' FAIL ', Color::WHITE, Color::RED);
         $this->console->writeLine($this->strColPad($descr, $this->width - 15, '              '), Color::RED);
     } elseif ($result instanceof Warning) {
         $this->console->write('       ');
         $this->console->write(' WARN ', Color::NORMAL, Color::YELLOW);
         $this->console->writeLine($this->strColPad($descr, $this->width - 15, '              '), Color::YELLOW);
     } else {
         $this->console->write('       ');
         $this->console->write(' ???? ', Color::NORMAL, Color::YELLOW);
         $this->console->writeLine($this->strColPad($descr, $this->width - 7, '              '), Color::YELLOW);
     }
     $this->console->writeLine();
 }