lithium\test\Unit::run()
Runs the test methods in this test case, with the given options.
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.
Parameters
-
array
$options
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.
Returns
arrayLinks
Source
public function run(array $options = []) {
$defaults = [
'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 = [];
$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;
}