Added tests to prove that Dispatcher.afterDispatch event is dispatched by exception renderer on error response

This commit is contained in:
Kim Biesbjerg 2016-07-14 00:17:02 +02:00
parent bddff7d2b0
commit 5a63ee4e3e

View file

@ -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);
}
}