mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Dispatch Controller.shutdown instead of calling afterFilter directly. Updated test
This commit is contained in:
parent
a05639a30e
commit
c77b628841
2 changed files with 14 additions and 28 deletions
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue