From 5f47dab73eb84ea21c8f41ebd8dff270db5ae061 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Tue, 11 Dec 2012 15:42:17 +0400 Subject: [PATCH] Use new logError in FrontController, tests --- app/ErrorAction.php | 24 +----------------------- app/FrontController.php | 1 + tests/app/FrontControllerTest.php | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/app/ErrorAction.php b/app/ErrorAction.php index f85a8d6..a4befde 100644 --- a/app/ErrorAction.php +++ b/app/ErrorAction.php @@ -63,29 +63,7 @@ class ErrorAction extends Action protected function logError() { if ($this->template == 500) { - $error = 0; - $ex = $this->exception; - if ($ex instanceof ErrorException) { - $error = $ex->getSeverity(); - } - - switch ($error) { - case E_NOTICE: - $error = 'Notice'; - break; - case E_WARNING: - $error = 'Warning'; - break; - case E_ERROR: - $error = 'Fatal Error'; - break; - default: - $error = 'Unknown Error'; - break; - } - $message = 'PHP ' . $error . ': ' . $ex->getMessage() . ' in ' . $ex->getFile() - . ' on line ' . $ex->getLine(); - error_log($message); + ErrorHandler::logError($this->exception); } } diff --git a/app/FrontController.php b/app/FrontController.php index 2fe5889..dc0e79a 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -143,6 +143,7 @@ class FrontController header('HTTP/1.0 500 Internal Server Error'); } } + ErrorHandler::logError($e); return ErrorHandler::showDebug($e); } $layout_class = $this->getRouter()->getErrorLayout(); diff --git a/tests/app/FrontControllerTest.php b/tests/app/FrontControllerTest.php index 78da6a6..55709a1 100644 --- a/tests/app/FrontControllerTest.php +++ b/tests/app/FrontControllerTest.php @@ -28,6 +28,7 @@ require_once dirname(__FILE__) . '/../../app/AjaxAction.php'; class FrontControllerTest extends PHPUnit_Framework_TestCase { + protected $log_file_name = 'error_log_file'; public function run(PHPUnit_Framework_TestResult $result = NULL) { @@ -141,11 +142,14 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase public function testExecuteNoRouteDebug() { $this->setConstants(true); + ini_set('error_log', $this->log_file_name); $controller = FrontController::getInstance(); $result = $controller->execute(); $this->assertNotEmpty($result); $this->assertContains('Route for "" not found', $result); $this->assertContains('Error404Exception', $result); + $error = file_get_contents($this->log_file_name); + $this->assertContains('PHP Unknown Error: Route for "" not found', $error); } /** @@ -155,11 +159,14 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase { $_SERVER['REQUEST_URI'] = '/user/account/213'; $this->setConstants(true); + ini_set('error_log', $this->log_file_name); $controller = FrontController::getInstance(); $router = $controller->getRouter(); $router->add('user', 'user/account/:id', 'user'); $result = $controller->execute(); $this->assertContains('Action class "userAction" not found.', $result); + $error = file_get_contents($this->log_file_name); + $this->assertContains('PHP Unknown Error: Action class "userAction" not found.', $error); } /** @@ -170,11 +177,14 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase $this->getMock('userAction'); $_SERVER['REQUEST_URI'] = '/user/account/213'; $this->setConstants(true); + ini_set('error_log', $this->log_file_name); $controller = FrontController::getInstance(); $router = $controller->getRouter(); $router->add('user', 'user/account/:id', 'user'); $result = $controller->execute(); $this->assertContains('Layout class "DefaultLayout" not found.', $result); + $error = file_get_contents($this->log_file_name); + $this->assertContains('PHP Unknown Error: Layout class "DefaultLayout" not found.', $error); } /** @@ -267,6 +277,10 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase public function tearDown() { unset_new_overload(); + if (file_exists($this->log_file_name) && is_writable($this->log_file_name)) { + unlink($this->log_file_name); + } + ini_set('error_log', 'php://stderr'); } protected function newCallback($className)