Skip to content

Commit

Permalink
#10218 Fix tests to prevent future regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
fquffio committed Feb 14, 2017
1 parent 3171243 commit a3fe3fe
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/TestCase/Error/ExceptionRendererTest.php
Expand Up @@ -731,23 +731,23 @@ public function testRenderExceptionInBeforeRender()
*/
public function testMissingLayoutPathRenderSafe()
{
$eventTriggered = false;
$exception = new NotFoundException();
$ExceptionRenderer = new ExceptionRenderer($exception);

$ExceptionRenderer->controller = $this->getMockBuilder('Cake\Controller\Controller')
->setMethods(['render'])
->getMock();
$ExceptionRenderer->controller = new Controller();
$ExceptionRenderer->controller->helpers = ['Fail', 'Boom'];
$ExceptionRenderer->controller->eventManager()->on('Controller.beforeRender', function (Event $event) {
$event->subject()->viewBuilder()->layoutPath('boom');
});
$ExceptionRenderer->controller->eventManager()->on(
'Controller.beforeRender',
function (Event $event) use ($exception, &$eventTriggered) {
$eventTriggered = true;
$event->subject()->viewBuilder()->layoutPath('boom');

throw $exception;
}
);
$ExceptionRenderer->controller->request = new Request;

$ExceptionRenderer->controller->expects($this->once())
->method('render')
->with('error400')
->will($this->throwException($exception));

$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
$response->expects($this->once())
->method('body')
Expand All @@ -761,6 +761,9 @@ public function testMissingLayoutPathRenderSafe()
$ExceptionRenderer->render();
$this->assertEquals('', $ExceptionRenderer->controller->viewBuilder()->layoutPath());
$this->assertEquals('Error', $ExceptionRenderer->controller->viewBuilder()->templatePath());

// Just to ensure the callback has actually been triggered, so we're actually testing something:
$this->assertTrue($eventTriggered);
}

/**
Expand Down

0 comments on commit a3fe3fe

Please sign in to comment.