mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Added tests to prove that Dispatcher.afterDispatch event is dispatched by exception renderer on error response
This commit is contained in:
parent
bddff7d2b0
commit
5a63ee4e3e
1 changed files with 42 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue