Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac74c9a

Browse filesBrowse files
bug #27687 [HttpKernel] fix argument's error messages in ServiceValueResolver (nicolas-grekas)
This PR was merged into the 4.1 branch. Discussion ---------- [HttpKernel] fix argument's error messages in ServiceValueResolver | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27625 | License | MIT | Doc PR | - Forgotten while renamed to hidden services. Commits ------- aa50ffc [HttpKernel] fix argument's error messages in ServiceValueResolver
2 parents 4660857 + aa50ffc commit ac74c9a
Copy full SHA for ac74c9a

File tree

2 files changed

+29
-1
lines changed
Filter options

2 files changed

+29
-1
lines changed

‎src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function resolve(Request $request, ArgumentMetadata $argument)
6868
yield $this->container->get($controller)->get($argument->getName());
6969
} catch (RuntimeException $e) {
7070
$what = sprintf('argument $%s of "%s()"', $argument->getName(), $controller);
71-
$message = preg_replace('/service "service_locator\.[^"]++"/', $what, $e->getMessage());
71+
$message = preg_replace('/service "\.service_locator\.[^"]++"/', $what, $e->getMessage());
7272

7373
if ($e->getMessage() === $message) {
7474
$message = sprintf('Cannot resolve %s: %s', $what, $message);

‎src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\ServiceLocator;
1617
use Symfony\Component\HttpFoundation\Request;
1718
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver;
1819
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
20+
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
1921

2022
class ServiceValueResolverTest extends TestCase
2123
{
@@ -85,6 +87,25 @@ public function testControllerNameIsAnArray()
8587
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
8688
}
8789

90+
/**
91+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
92+
* @expectedExceptionMessage Cannot autowire argument $dummy of "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyController::index()": it references class "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyService" but no such service exists.
93+
*/
94+
public function testErrorIsTruncated()
95+
{
96+
$container = new ContainerBuilder();
97+
$container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
98+
99+
$container->register('argument_resolver.service', ServiceValueResolver::class)->addArgument(null)->setPublic(true);
100+
$container->register(DummyController::class)->addTag('controller.service_arguments')->setPublic(true);
101+
102+
$container->compile();
103+
104+
$request = $this->requestWithAttributes(array('_controller' => array(DummyController::class, 'index')));
105+
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
106+
$container->get('argument_resolver.service')->resolve($request, $argument)->current();
107+
}
108+
88109
private function requestWithAttributes(array $attributes)
89110
{
90111
$request = Request::create('/');
@@ -110,3 +131,10 @@ private function assertYieldEquals(array $expected, \Generator $generator)
110131
class DummyService
111132
{
112133
}
134+
135+
class DummyController
136+
{
137+
public function index(DummyService $dummy)
138+
{
139+
}
140+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.