From 5a63ee4e3e0daf076cf0f1e0dc957efa7fd9364e Mon Sep 17 00:00:00 2001 From: Kim Biesbjerg Date: Thu, 14 Jul 2016 00:17:02 +0200 Subject: [PATCH] Added tests to prove that Dispatcher.afterDispatch event is dispatched by exception renderer on error response --- .../Test/Case/Error/ExceptionRendererTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index 51cc4ef70..2bff49aea 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -20,6 +20,7 @@ App::uses('ExceptionRenderer', 'Error'); App::uses('Controller', 'Controller'); App::uses('Component', 'Controller'); App::uses('Router', 'Routing'); +App::uses('CakeEvent', 'Event'); /** * Short description for class. @@ -61,6 +62,26 @@ class BlueberryComponent extends Component { } +/** + * AfterDispatchEventCallable class + * + * @package Cake.Test.Case.Error + */ +class AfterDispatchEventCallable { + + public $afterDispatchCalled = false; +/** + * AfterDispatchEventCallable::afterDispatch() + * + * @param mixed $event + * @return mixed boolean to stop the event dispatching or null to continue + */ + public function afterDispatch(CakeEvent $event) { + $this->afterDispatchCalled = true; + } + +} + /** * TestErrorController class * @@ -877,4 +898,25 @@ class ExceptionRendererTest extends CakeTestCase { $this->assertContains(h('SELECT * from poo_query < 5 and :seven'), $result); $this->assertContains("'seven' => (int) 7", $result); } + +/** + * Tests that exception renderer dispatches Dispatcher.afterDispatch event on error response + * + * @return void + */ + public function testAfterDispatchEventOnErrorResponse() { + $callable = new AfterDispatchEventCallable(); + Configure::write('Dispatcher.filters', array( + array('callable' => array($callable, 'afterDispatch'), 'on' => 'after') + )); + + $exception = new Exception('Oh no!'); + $ExceptionRenderer = new ExceptionRenderer($exception); + + ob_start(); + $ExceptionRenderer->render(); + $result = ob_get_clean(); + + $this->assertTrue($callable->afterDispatchCalled); + } }