Skip to content
Permalink
Browse files

Dispatch Controller.shutdown instead of calling afterFilter directly.…

… Updated test
  • Loading branch information...
biesbjerg committed Jul 14, 2016
1 parent a05639a commit c77b6288418fe504dee2491a8272a1255be5cfaa
Showing with 14 additions and 28 deletions.
  1. +2 −1 lib/Cake/Error/ExceptionRenderer.php
  2. +12 −27 lib/Cake/Test/Case/Error/ExceptionRendererTest.php
@@ -331,7 +331,8 @@ protected function _outputMessageSafe($template) {
}
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(
@@ -20,7 +20,7 @@
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 @@ public function initialize(Controller $controller) {
}
/**
* 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 @@ public function testPDOException() {
* @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();
};
$EventManager = CakeEventManager::instance();
$EventManager->attach($listener, 'Controller.shutdown');
$EventManager->attach($listener, 'Dispatcher.afterDispatch');
$exception = new Exception('Oh no!');
$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);
}
}

0 comments on commit c77b628

Please sign in to comment.
You can’t perform that action at this time.