lithium\test\Unit::run PHP Метод

run() публичный Метод

Installs a temporary error handler that will convert regular errors to exceptions in order to make both errors and exceptions be handled in a unified way. ErrorExceptions created like this, will get the error's code as their severity. As this comes closest to their meaning. The error handler honors the PHP error_level and will not convert errors to exceptions if they are masked by the error_level. This allows test methods to run assertions against i.e. deprecated functions. Usually the error_level is set by the test runner so that all errors are converted.
public run ( array $options = [] ) : array
$options array The options to use when running the test. Available options are: - `'methods'`: An arbitrary array of method names to execute. If unspecified, all methods starting with 'test' are run. - `'reporter'`: A closure which gets called after each test result, which may modify the results presented. - `'handler'`: A closure which gets registered as the temporary error handler.
Результат array
    public function run(array $options = array())
    {
        $defaults = array('methods' => $this->methods(), 'reporter' => $this->_reporter, 'handler' => function ($code, $message, $file = null, $line = null) {
            if (error_reporting() & $code) {
                throw new ErrorException($message, 0, $code, $file, $line);
            }
        });
        $options += $defaults;
        $this->_results = array();
        $this->_reporter = $options['reporter'];
        try {
            $this->skip();
        } catch (Exception $e) {
            $this->_handleException($e);
            return $this->_results;
        }
        set_error_handler($options['handler']);
        foreach ($options['methods'] as $method) {
            if ($this->_runTestMethod($method, $options) === false) {
                break;
            }
        }
        restore_error_handler();
        return $this->_results;
    }

Usage Example

Пример #1
0
 /**
  * This hack is a necessary optimization until these tests are properly mocked out.
  *
  * @param array $options Options for the parent class' method.
  */
 public function run(array $options = array())
 {
     $this->_results = array();
     try {
         $this->skip();
     } catch (Exception $e) {
         $this->_handleException($e);
         return $this->_results;
     }
     $this->_configs = Connections::config();
     $result = parent::run($options);
     Connections::get('lithium_mongo_test')->dropDB('lithium_test');
     Connections::reset();
     Connections::config($this->_configs);
     return $result;
 }