Пример #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);
     }
 }