Skip to content

Commit a3fe3fe

Browse files
committed
#10218 Fix tests to prevent future regressions
1 parent 3171243 commit a3fe3fe

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

tests/TestCase/Error/ExceptionRendererTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -731,23 +731,23 @@ public function testRenderExceptionInBeforeRender()
731731
*/
732732
public function testMissingLayoutPathRenderSafe()
733733
{
734+
$eventTriggered = false;
734735
$exception = new NotFoundException();
735736
$ExceptionRenderer = new ExceptionRenderer($exception);
736737

737-
$ExceptionRenderer->controller = $this->getMockBuilder('Cake\Controller\Controller')
738-
->setMethods(['render'])
739-
->getMock();
738+
$ExceptionRenderer->controller = new Controller();
740739
$ExceptionRenderer->controller->helpers = ['Fail', 'Boom'];
741-
$ExceptionRenderer->controller->eventManager()->on('Controller.beforeRender', function (Event $event) {
742-
$event->subject()->viewBuilder()->layoutPath('boom');
743-
});
740+
$ExceptionRenderer->controller->eventManager()->on(
741+
'Controller.beforeRender',
742+
function (Event $event) use ($exception, &$eventTriggered) {
743+
$eventTriggered = true;
744+
$event->subject()->viewBuilder()->layoutPath('boom');
745+
746+
throw $exception;
747+
}
748+
);
744749
$ExceptionRenderer->controller->request = new Request;
745750

746-
$ExceptionRenderer->controller->expects($this->once())
747-
->method('render')
748-
->with('error400')
749-
->will($this->throwException($exception));
750-
751751
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
752752
$response->expects($this->once())
753753
->method('body')
@@ -761,6 +761,9 @@ public function testMissingLayoutPathRenderSafe()
761761
$ExceptionRenderer->render();
762762
$this->assertEquals('', $ExceptionRenderer->controller->viewBuilder()->layoutPath());
763763
$this->assertEquals('Error', $ExceptionRenderer->controller->viewBuilder()->templatePath());
764+
765+
// Just to ensure the callback has actually been triggered, so we're actually testing something:
766+
$this->assertTrue($eventTriggered);
764767
}
765768

766769
/**

0 commit comments

Comments
 (0)