Skip to content

Commit

Permalink
Added tests to prove that Dispatcher.afterDispatch event is dispatche…
Browse files Browse the repository at this point in the history
…d by exception renderer on error response
  • Loading branch information
biesbjerg committed Jul 13, 2016
1 parent bddff7d commit 5a63ee4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/Cake/Test/Case/Error/ExceptionRendererTest.php
Expand Up @@ -20,6 +20,7 @@
App::uses('Controller', 'Controller');
App::uses('Component', 'Controller');
App::uses('Router', 'Routing');
App::uses('CakeEvent', 'Event');

/**
* Short description for class.
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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.