From c77b6288418fe504dee2491a8272a1255be5cfaa Mon Sep 17 00:00:00 2001 From: Kim Biesbjerg Date: Thu, 14 Jul 2016 04:51:49 +0200 Subject: [PATCH] Dispatch Controller.shutdown instead of calling afterFilter directly. Updated test --- lib/Cake/Error/ExceptionRenderer.php | 3 +- .../Test/Case/Error/ExceptionRendererTest.php | 39 ++++++------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 40f551417..4da938167 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -331,7 +331,8 @@ class ExceptionRenderer { } protected function _shutdown() { - $this->controller->afterFilter(); + $afterFilterEvent = new CakeEvent('Controller.shutdown', $this->controller); + $this->controller->getEventManager()->dispatch($afterFilterEvent); $Dispatcher = new Dispatcher(); $afterDispatchEvent = new CakeEvent('Dispatcher.afterDispatch', $Dispatcher, array( diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index abd620d68..9decaa7e5 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -20,7 +20,7 @@ App::uses('ExceptionRenderer', 'Error'); App::uses('Controller', 'Controller'); App::uses('Component', 'Controller'); App::uses('Router', 'Routing'); -App::uses('CakeEvent', 'Event'); +App::uses('CakeEventManager', 'Event'); /** * Short description for class. @@ -62,26 +62,6 @@ 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 * @@ -905,18 +885,23 @@ class ExceptionRendererTest extends CakeTestCase { * @return void */ public function testAfterDispatchEventOnErrorResponse() { - $callable = new AfterDispatchEventCallable(); - Configure::write('Dispatcher.filters', array( - array('callable' => array($callable, 'afterDispatch'), 'on' => 'after') - )); + $fired = array(); + $listener = function ($event) use (&$fired) { + $fired[] = $event->name(); + }; - $exception = new Exception('Oh no!'); + $EventManager = CakeEventManager::instance(); + $EventManager->attach($listener, 'Controller.shutdown'); + $EventManager->attach($listener, 'Dispatcher.afterDispatch'); + + $exception = new Exception('Terrible'); $ExceptionRenderer = new ExceptionRenderer($exception); ob_start(); $ExceptionRenderer->render(); ob_get_clean(); - $this->assertTrue($callable->afterDispatchCalled); + $expected = array('Controller.shutdown', 'Dispatcher.afterDispatch'); + $this->assertEquals($expected, $fired); } }