Skip to content

Commit

Permalink
[HttpKernel] Fix message for unresovable arguments of invokable contr…
Browse files Browse the repository at this point in the history
…ollers
  • Loading branch information
fancyweb committed Nov 21, 2022
1 parent 0924172 commit bc62d95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
}

if (!$this->container->has($controller)) {
$i = strrpos($controller, ':');
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
$controller = (false !== $i = strrpos($controller, ':'))
? substr($controller, 0, $i).strtolower(substr($controller, $i))
: $controller.'::__invoke';
}

$what = sprintf('argument $%s of "%s()"', $argument->getName(), $controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ public function testControllerNameIsAnArray()
$resolver->resolve($request, $argument);
}

public function testInvokableController()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Could not resolve argument $dummy of "App\Controller\Mine::__invoke()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?');
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => 'App\Controller\Mine']);
$this->assertTrue($resolver->supports($request, $argument));
$resolver->resolve($request, $argument);
}

private function requestWithAttributes(array $attributes)
{
$request = Request::create('/');
Expand Down

0 comments on commit bc62d95

Please sign in to comment.