mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #3809 from renan/2.5-non-integer-exception-code
Exiting with 1 when Exception::getCode() returns non-integer values.
This commit is contained in:
commit
8e9c85ef61
2 changed files with 30 additions and 1 deletions
|
@ -58,7 +58,9 @@ class ConsoleErrorHandler {
|
|||
$exception->getMessage(),
|
||||
$exception->getTraceAsString()
|
||||
));
|
||||
return $this->_stop($exception->getCode() ? $exception->getCode() : 1);
|
||||
$code = $exception->getCode();
|
||||
$code = ($code && is_integer($code)) ? $code : 1;
|
||||
return $this->_stop($code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -147,4 +147,31 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
|
|||
$this->Error->handleException($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* test a exception with non-integer code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNonIntegerExceptionCode() {
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
$this->markTestSkipped('ReflectionProperty::setAccessible() is available since 5.3');
|
||||
}
|
||||
|
||||
$exception = new Exception('Non-integer exception code');
|
||||
|
||||
$class = new ReflectionClass('Exception');
|
||||
$property = $class->getProperty('code');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($exception, '42S22');
|
||||
|
||||
ConsoleErrorHandler::$stderr->expects($this->once())->method('write')
|
||||
->with($this->stringContains('Non-integer exception code'));
|
||||
|
||||
$this->Error->expects($this->once())
|
||||
->method('_stop')
|
||||
->with(1);
|
||||
|
||||
$this->Error->handleException($exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue