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

[DI] Show the right class autowired when providing a non-existing class #32040

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
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 @@ -379,13 +379,14 @@ private function createTypeNotFoundMessageCallback(TypedReference $reference, $l
$container->setAliases($this->container->getAliases());
$container->setDefinitions($this->container->getDefinitions());
$container->setResourceTracking(false);
$currentId = $this->currentId;

return function () use ($container, $reference, $label) {
return $this->createTypeNotFoundMessage($container, $reference, $label);
return function () use ($container, $reference, $label, $currentId) {
return $this->createTypeNotFoundMessage($container, $reference, $label, $currentId);
};
}

private function createTypeNotFoundMessage(ContainerBuilder $container, TypedReference $reference, $label)
private function createTypeNotFoundMessage(ContainerBuilder $container, TypedReference $reference, $label, string $currentId)
{
if (!$r = $container->getReflectionClass($type = $reference->getType(), false)) {
// either $type does not exist or a parent class does not exist
Expand All @@ -409,7 +410,7 @@ private function createTypeNotFoundMessage(ContainerBuilder $container, TypedRef
}
}

$message = sprintf('Cannot autowire service "%s": %s %s', $this->currentId, $label, $message);
$message = sprintf('Cannot autowire service "%s": %s %s', $currentId, $label, $message);

if (null !== $this->lastFailure) {
$message = $this->lastFailure."\n".$message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ public function testProcess()
$this->assertEquals(Foo::class, (string) $container->getDefinition('bar')->getArgument(0));
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessage Cannot autowire service "Symfony\Component\DependencyInjection\Tests\CompilerEslaAction": argument "$notExisting" of method "Symfony\Component\DependencyInjection\Tests\Compiler\ElsaAction::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotExisting" but this class was not found.
*/
public function testProcessNotExistingActionParam()
{
$container = new ContainerBuilder();

$container->register(Foo::class);
$barDefinition = $container->register(__NAMESPACE__.'EslaAction', __NAMESPACE__.'\ElsaAction');
$barDefinition->setAutowired(true);

(new ResolveClassPass())->process($container);
(new AutowirePass())->process($container);
}

public function testProcessVariadic()
{
$container = new ContainerBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Symfony\Component\DependencyInjection\Tests\Fixtures;

class ConstructNotExists
{
public function __construct(NotExist $notExist)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,10 @@ public function __construct(LoggerInterface $logger, DecoratorInterface $decorat
{
}
}

final class ElsaAction
{
public function __construct(NotExisting $notExisting)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
public: true
autowire: true
autoconfigure: true

Symfony\Component\DependencyInjection\Tests\Fixtures\ConstructNotExists: ~
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,18 @@ public function testBindings()
], array_map(function (BoundArgument $v) { return $v->getValues()[0]; }, $definition->getBindings()));
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Cannot autowire service "Symfony\Component\DependencyInjection\Tests\Fixtures\ConstructNotExists": argument "$notExist" of method "__construct()" has type "Symfony\Component\DependencyInjection\Tests\Fixtures\NotExist" but this class was not found.
*/
public function testProcessNotExistingActionParam()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services_not_existing.yml');
$container->compile();
}

public function testFqcnLazyProxy()
{
$container = new ContainerBuilder();
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.