Browse Source

Show the incorrect type received, in error message

ADmad 6 years ago
parent
commit
a8b1b97d61
2 changed files with 9 additions and 4 deletions
  1. 5 3
      src/Controller/Controller.php
  2. 4 1
      tests/TestCase/Controller/ControllerTest.php

+ 5 - 3
src/Controller/Controller.php

@@ -517,9 +517,11 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
         }
 
         if (!$result instanceof ResponseInterface) {
-            throw new UnexpectedValueException(
-                'Controller actions can only return ResponseInterface instance or null.'
-            );
+            throw new UnexpectedValueException(sprintf(
+                'Controller actions can only return ResponseInterface instance or null. '
+                . 'Got %s instead.',
+                getTypeName($result)
+            ));
         }
 
         return $this->response = $result;

+ 4 - 1
tests/TestCase/Controller/ControllerTest.php

@@ -764,7 +764,10 @@ class ControllerTest extends TestCase
     public function testInvokeActionException()
     {
         $this->expectException(\UnexpectedValueException::class);
-        $this->expectExceptionMessage('Controller actions can only return ResponseInterface instance or null');
+        $this->expectExceptionMessage(
+            'Controller actions can only return ResponseInterface instance or null. '
+            . 'Got string instead.'
+        );
 
         $url = new ServerRequest([
             'url' => 'test/willCauseException',