Skip to content
Permalink
Browse files

Added tests to prove that Dispatcher.afterDispatch event is dispatche…

…d by exception renderer on error response
  • Loading branch information...
biesbjerg committed Jul 13, 2016
1 parent bddff7d commit 5a63ee4e3e0daf076cf0f1e0dc957efa7fd9364e
Showing with 42 additions and 0 deletions.
  1. +42 −0 lib/Cake/Test/Case/Error/ExceptionRendererTest.php
@@ -20,6 +20,7 @@
App::uses('Controller', 'Controller');
App::uses('Component', 'Controller');
App::uses('Router', 'Routing');
App::uses('CakeEvent', 'Event');
/**
* Short description for class.
@@ -61,6 +62,26 @@ 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
*
@@ -877,4 +898,25 @@ public function testPDOException() {
$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);
}
}

0 comments on commit 5a63ee4

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