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

[DependencyInjection] Fix wrong exception when service is synthetic #33625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ protected function processValue($value, $isRoot = false)
*/
protected function getConstructor(Definition $definition, $required)
{
if ($definition->isSynthetic()) {
return null;
}

if (\is_string($factory = $definition->getFactory())) {
if (!\function_exists($factory)) {
throw new RuntimeException(sprintf('Invalid service "%s": function "%s" does not exist.', $this->currentId, $factory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,10 @@ public function testSetterInjection()
);
}

/**
* @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist.
*/
public function testWithNonExistingSetterAndAutowiring()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass": method "setLogger()" does not exist.');
$container = new ContainerBuilder();

$definition = $container->register(CaseSensitiveClass::class, CaseSensitiveClass::class)->setAutowired(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass;
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
Expand Down Expand Up @@ -110,12 +112,10 @@ public function testScalarSetter()
$this->assertEquals([['setDefaultLocale', ['fr']]], $definition->getMethodCalls());
}

/**
* @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist.
*/
public function testWithNonExistingSetterAndBinding()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist.');
$container = new ContainerBuilder();

$bindings = [
Expand All @@ -129,4 +129,25 @@ public function testWithNonExistingSetterAndBinding()
$pass = new ResolveBindingsPass();
$pass->process($container);
}

public function testSyntheticServiceWithBind()
{
$container = new ContainerBuilder();
$argument = new BoundArgument('bar');

$container->register('foo', 'stdClass')
->addArgument(new Reference('synthetic.service'));

$container->register('synthetic.service')
->setSynthetic(true)
->setBindings(['$apiKey' => $argument]);

$container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class)
->setBindings(['$apiKey' => $argument]);

(new ResolveBindingsPass())->process($container);
(new DefinitionErrorExceptionPass())->process($container);

$this->assertSame([1 => 'bar'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.