Browse Source

Pass exception as argument to hook method.

Improve test. Refs #17960
ADmad 1 year ago
parent
commit
f1b166b0d0

+ 1 - 1
src/Error/Renderer/WebExceptionRenderer.php

@@ -425,7 +425,7 @@ class WebExceptionRenderer implements ExceptionRendererInterface
                 $this->controller->viewBuilder()->setTemplate($method);
 
                 $reflectionMethod = new ReflectionMethod($this->controller, $method);
-                $result = $reflectionMethod->invoke($this->controller);
+                $result = $reflectionMethod->invoke($this->controller, $this->error);
 
                 if ($result instanceof Response) {
                     $this->controller->setResponse($result);

+ 1 - 1
tests/TestCase/Error/Renderer/WebExceptionRendererTest.php

@@ -982,7 +982,7 @@ class WebExceptionRendererTest extends TestCase
         $exceptionRenderer = new TestAppsExceptionRenderer($exception);
 
         $result = (string)$exceptionRenderer->render()->getBody();
-        $this->assertStringContainsString('template for MissingWidgetThing was rendered', $result);
+        $this->assertStringContainsString('template for TestApp\Error\Exception\MissingWidgetThingException was rendered', $result);
 
         $exception = new XmlException();
         $exceptionRenderer = new TestAppsExceptionRenderer($exception);

+ 4 - 1
tests/test_app/TestApp/Controller/TestAppsErrorController.php

@@ -5,11 +5,14 @@ namespace TestApp\Controller;
 
 use Cake\Controller\ErrorController;
 use Cake\Http\Response;
+use TestApp\Error\Exception\MissingWidgetThingException;
 
 class TestAppsErrorController extends ErrorController
 {
-    protected function missingWidgetThing()
+    protected function missingWidgetThing(MissingWidgetThingException $exception)
     {
+        assert($this->viewBuilder()->getVar('error') === $exception);
+
         $this->viewBuilder()->setLayout('default');
     }
 

+ 1 - 1
tests/test_app/templates/Error/missing_widget_thing.php

@@ -1 +1 @@
-template for MissingWidgetThing was rendered
+template for <?= get_class($error) ?> was rendered