Browse Source

Improve error message.

Mark Story 4 years ago
parent
commit
a1d3b76ba3

+ 1 - 0
src/Controller/ControllerFactory.php

@@ -197,6 +197,7 @@ class ControllerFactory implements ControllerFactoryInterface, RequestHandlerInt
                 throw new InvalidParameterException([
                     'template' => 'missing_dependency',
                     'parameter' => $parameter->getName(),
+                    'type' => $typeName,
                     'controller' => $this->controller->getName(),
                     'action' => $this->controller->getRequest()->getParam('action'),
                     'prefix' => $this->controller->getRequest()->getParam('prefix'),

+ 1 - 1
src/Controller/Exception/InvalidParameterException.php

@@ -27,7 +27,7 @@ class InvalidParameterException extends CakeException
      */
     protected $templates = [
         'failed_coercion' => 'Unable to coerce "%s" to `%s` for `%s` in action %s::%s().',
-        'missing_dependency' => 'Failed to inject dependency from service container for `%s` in action %s::%s().',
+        'missing_dependency' => 'Failed to inject dependency from service container for parameter `%s` with type `%s` in action %s::%s().',
         'missing_parameter' => 'Missing passed parameter for `%s` in action %s::%s().',
         'unsupported_type' => 'Type declaration for `%s` in action %s::%s() is unsupported.',
     ];

+ 3 - 1
tests/TestCase/Controller/ControllerFactoryTest.php

@@ -530,7 +530,9 @@ class ControllerFactoryTest extends TestCase
         $controller = $this->factory->create($request);
 
         $this->expectException(InvalidParameterException::class);
-        $this->expectExceptionMessage('Failed to inject dependency from service container for `dep` in action Dependencies::requiredDep()');
+        $this->expectExceptionMessage(
+            'Failed to inject dependency from service container for parameter `dep` with type `stdClass` in action Dependencies::requiredDep()'
+        );
         $this->factory->invoke($controller);
     }