Skip to content
Permalink
Browse files

Ensure ConsoleErrorHandler exits with code 1 for exceptions with stri…

…ng codes.

Code was messed up during 2.6 => 3.0 merge.
  • Loading branch information...
ADmad committed Jul 3, 2014
1 parent 4275717 commit b31fb19dfdb069543487f9f8b93596e2d61ff998
Showing with 20 additions and 7 deletions.
  1. +17 −0 src/Console/ConsoleErrorHandler.php
  2. +3 −7 tests/TestCase/Console/ConsoleErrorHandlerTest.php
@@ -50,6 +50,23 @@ public function __construct($options = []) {
$this->_options = $options;
}
/**
* Handle errors in the console environment. Writes errors to stderr,
* and logs messages if Configure::read('debug') is false.
*
* @param \Exception $exception Exception instance.
* @return void
* @throws Exception When renderer class not found
* @see http://php.net/manual/en/function.set-exception-handler.php
*/
public function handleException(\Exception $exception) {
$this->_displayException($exception);
$this->_logException($exception);
$code = $exception->getCode();
$code = ($code && is_int($code)) ? $code : 1;
$this->_stop($code);
}
/**
* Prints an exception to stderr.
*
@@ -141,18 +141,14 @@ public function testError500Exception() {
* @return void
*/
public function testNonIntegerExceptionCode() {
if (PHP_VERSION_ID < 50300) {
$this->markTestSkipped('ReflectionProperty::setAccessible() is available since 5.3');
}
$exception = new Error\Exception('Non-integer exception code');
$exception = new Exception('Non-integer exception code');
$class = new ReflectionClass('Exception');
$class = new \ReflectionClass('Exception');
$property = $class->getProperty('code');
$property->setAccessible(true);
$property->setValue($exception, '42S22');
ConsoleErrorHandler::$stderr->expects($this->once())->method('write')
$this->stderr->expects($this->once())->method('write')
->with($this->stringContains('Non-integer exception code'));
$this->Error->expects($this->once())

0 comments on commit b31fb19

Please sign in to comment.
You can’t perform that action at this time.