From aa0bad924724e2f9d7e60a27e0e343665b7feff5 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 2 Dec 2010 01:44:31 -0200 Subject: [PATCH] Ignore errorHandler if warning suppressor (@command()) is used. --- cake/console/libs/console_error_handler.php | 3 +++ cake/libs/error/error_handler.php | 3 +++ .../tests/cases/libs/error/error_handler.test.php | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/cake/console/libs/console_error_handler.php b/cake/console/libs/console_error_handler.php index f70e34e6d..4a7b6ceed 100644 --- a/cake/console/libs/console_error_handler.php +++ b/cake/console/libs/console_error_handler.php @@ -70,6 +70,9 @@ class ConsoleErrorHandler extends ErrorHandler { * @return void */ public static function handleError($code, $description, $file = null, $line = null, $context = null) { + if (error_reporting() === 0) { + return; + } $stderr = self::getStderr(); list($name, $log) = self::_mapErrorCode($code); $message = sprintf(__('%s in [%s, line %s]'), $description, $file, $line); diff --git a/cake/libs/error/error_handler.php b/cake/libs/error/error_handler.php index daa6b3234..85cea7ec4 100644 --- a/cake/libs/error/error_handler.php +++ b/cake/libs/error/error_handler.php @@ -135,6 +135,9 @@ class ErrorHandler { * @return boolean true if error was handled */ public static function handleError($code, $description, $file = null, $line = null, $context = null) { + if (error_reporting() === 0) { + return false; + } $errorConfig = Configure::read('Error'); list($error, $log) = self::_mapErrorCode($code); diff --git a/cake/tests/cases/libs/error/error_handler.test.php b/cake/tests/cases/libs/error/error_handler.test.php index c95d7566a..736524251 100644 --- a/cake/tests/cases/libs/error/error_handler.test.php +++ b/cake/tests/cases/libs/error/error_handler.test.php @@ -113,6 +113,21 @@ class ErrorHandlerTest extends CakeTestCase { $this->assertPattern('/' . $expected . '<\/b>/', $result); } +/** + * test error prepended by @ + * + * @return void + */ + function testErrorSuppressed() { + set_error_handler('ErrorHandler::handleError'); + $this->_restoreError = true; + + ob_start(); + @include 'invalid.file'; + $result = ob_get_clean(); + $this->assertTrue(empty($result)); + } + /** * Test that errors go into CakeLog when debug = 0. *