Browse Source

#10218 Fix tests to prevent future regressions

Paolo Cuffiani 9 years ago
parent
commit
a3fe3fe23b
1 changed files with 14 additions and 11 deletions
  1. 14 11
      tests/TestCase/Error/ExceptionRendererTest.php

+ 14 - 11
tests/TestCase/Error/ExceptionRendererTest.php

@@ -731,23 +731,23 @@ class ExceptionRendererTest extends TestCase
      */
     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')
@@ -761,6 +761,9 @@ class ExceptionRendererTest extends TestCase
         $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);
     }
 
     /**