From e6735dc1584e3dfa27108d9805def756522816f7 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 4 Jun 2012 16:09:45 +0400 Subject: [PATCH] added setException method to ErrorLayout class --- layout/Error.layout.php | 17 ++++++++- tests/layout/ErrorLayoutTest.php | 82 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 tests/layout/ErrorLayoutTest.php diff --git a/layout/Error.layout.php b/layout/Error.layout.php index d8fe312..c50b866 100644 --- a/layout/Error.layout.php +++ b/layout/Error.layout.php @@ -11,5 +11,20 @@ class ErrorLayout extends Layout { - protected function execute(){} + /** + * @var GeneralException + */ + protected $exception; + + protected function execute() + { + } + + /** + * @param GeneralException $exception + */ + public function setException(GeneralException $exception) + { + $this->exception = $exception; + } } \ No newline at end of file diff --git a/tests/layout/ErrorLayoutTest.php b/tests/layout/ErrorLayoutTest.php new file mode 100644 index 0000000..4efb16f --- /dev/null +++ b/tests/layout/ErrorLayoutTest.php @@ -0,0 +1,82 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage UnitTests + * @since 04-06-2012 + * @user: agrebnev + */ + +require_once dirname(__FILE__) . '/../../exception/ErrorHandler.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; +require_once dirname(__FILE__) . '/../../app/FrontController.php'; +require_once dirname(__FILE__) . '/../../layout/Layout.php'; +require_once dirname(__FILE__) . '/../../layout/Error.layout.php'; + +/** + * @runTestsInSeparateProcesses + */ +class ErrorLayoutTest extends PHPUnit_Framework_TestCase +{ + + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + $this->setPreserveGlobalState(false); + return parent::run($result); + } + + public function setUp() + { + if (!class_exists('RouterMock')) { + $this->getMock('Router', array(), array(), 'RouterMock', false); + } + if (!class_exists('PHPViewMock')) { + $this->getMock('PHPView', array('fetch', 'append', 'prepend', 'assign', 'getTemplate'), array(), 'PHPViewMock', false); + } + + set_new_overload(array($this, 'newCallback')); + } + + public function testSetException() + { + if (!defined('DEBUG')) { + define('DEBUG', false); + } + $layout = new ErrorLayout(); + $layout->setException(new GeneralException()); + $this->assertAttributeInstanceOf('GeneralException', 'exception', $layout); + } + + public function testExecute() + { + if (!defined('DEBUG')) { + define('DEBUG', false); + } + $action = $this->getMock('Action', array('fetch')); + $action->expects($this->once()) + ->method('fetch') + ->will($this->returnValue('this is the result of Action::fetch()')); + + $layout = new ErrorLayout(); + $layout->fetch($action); + } + + + protected function newCallback($className) + { + switch ($className) { + case 'Router': + return 'RouterMock'; + case 'PHPView': + return 'PHPViewMock'; + default: + return $className; + } + } + + public function tearDown() + { + unset_new_overload(); + } +}