From d33f676ddd72b798fba3aff6fdf58ba1a7bdf445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Fri, 14 Sep 2012 14:17:07 +0200 Subject: [PATCH] Handling a fatal error on console should call Shell::_stop(1). Just like we do on web, any exception or fatal error will result into a InternalErrorException/FatalErrorException. --- lib/Cake/Console/ConsoleErrorHandler.php | 4 ++++ .../Case/Console/ConsoleErrorHandlerTest.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/Cake/Console/ConsoleErrorHandler.php b/lib/Cake/Console/ConsoleErrorHandler.php index 043c62125..e7409e891 100644 --- a/lib/Cake/Console/ConsoleErrorHandler.php +++ b/lib/Cake/Console/ConsoleErrorHandler.php @@ -84,6 +84,10 @@ class ConsoleErrorHandler { if (Configure::read('debug') == 0) { CakeLog::write($log, $message); } + + if ($log === LOG_ERR) { + $this->_stop(1); + } } /** diff --git a/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php b/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php index ef24dcbcf..32cddd4b0 100644 --- a/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php +++ b/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php @@ -60,6 +60,23 @@ class ConsoleErrorHandlerTest extends CakeTestCase { $this->Error->handleError(E_NOTICE, 'This is a notice error', '/some/file', 275); } +/** + * test that the console error handler can deal with fatal errors. + * + * @return void + */ + public function testHandleFatalError() { + $content = "Fatal Error Error: This is a fatal error in [/some/file, line 275]\n"; + ConsoleErrorHandler::$stderr->expects($this->once())->method('write') + ->with($content); + + $this->Error->expects($this->once()) + ->method('_stop') + ->with(1); + + $this->Error->handleError(E_USER_ERROR, 'This is a fatal error', '/some/file', 275); + } + /** * test that the console error handler can deal with CakeExceptions. *