From 1d999bda3f95077d8e0635c02da0a621f55c5423 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 4 Jun 2012 16:09:16 +0400 Subject: [PATCH] modified FrontController to get error layout from Router --- app/FrontController.php | 16 ++++++++++++---- tests/app/FrontControllerTest.php | 8 +++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/FrontController.php b/app/FrontController.php index 23cc62e..4e79609 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -41,8 +41,10 @@ class FrontController /** * Refuse cloning */ - private function __clone(){} - + private function __clone() + { + } + /** * @return FrontController */ @@ -126,14 +128,20 @@ class FrontController } } return $html; - } catch(Exception $e) { + } catch (Exception $e) { if (DEBUG == true) { if (!headers_sent()) { header('HTTP/1.0 500 Internal Server Error'); } return ErrorHandler::showDebug($e); } - $layout = new ErrorLayout(); + $layout_class = $this->getRouter()->getErrorLayout(); + + /** + * @var ErrorLayout $layout + */ + $layout = new $layout_class(); + $layout->setException($e); return $layout->fetch(new ErrorAction($e)); } } diff --git a/tests/app/FrontControllerTest.php b/tests/app/FrontControllerTest.php index 7f2d4bc..59b0c8f 100644 --- a/tests/app/FrontControllerTest.php +++ b/tests/app/FrontControllerTest.php @@ -44,7 +44,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase $this->getMock('View'); } if (!class_exists('ErrorLayout')) { - $this->getMock('ErrorLayout', array('fetch'), array(), 'ErrorLayoutMock'); + $this->getMock('ErrorLayout', array('fetch', 'setException'), array(), 'ErrorLayoutMock'); } if (!class_exists('ErrorActionMock')) { $this->getMock('ErrorAction', array(), array(), 'ErrorActionMock', false); @@ -190,7 +190,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase $router = $controller->getRouter(); $router->add('user', 'user/account/:id', 'user'); $result = $controller->execute(); - $this->assertEmpty($result); + $this->assertNull($result); } /** * @runInSeparateProcess @@ -205,7 +205,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase $router = $controller->getRouter(); $router->add('user', 'user/account/:id', 'NewAjax'); $result = $controller->execute(); - $this->assertEmpty($result); + $this->assertNull($result); } private function setConstants($val = false) @@ -227,8 +227,6 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase return 'PHPViewMock'; case 'DefaultLayout': return 'DefaultLayoutMock'; - case 'userAction': - return 'userAction'; case 'ErrorAction': return 'ErrorActionMock'; case 'ErrorLayout':