Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit1ffdb50

Browse files
committed
[DI] Do not suggest writing an implementation when multiple exist
1 parent3d5f04c commit1ffdb50

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,11 @@ private function createTypeNotFoundMessage(TypedReference $reference, $label)
462462

463463
$message =sprintf('has type "%s" but this class %s.',$type,$parentMsg ?sprintf('is missing a parent class (%s)',$parentMsg) :'was not found');
464464
}else {
465+
$alternatives =$this->createTypeAlternatives($reference);
465466
$message =$this->container->has($type) ?'this service is abstract' :'no such service exists';
466-
$message =sprintf('references %s "%s" but %s.%s',$r->isInterface() ?'interface' :'class',$type,$message,$this->createTypeAlternatives($reference));
467+
$message =sprintf('references %s "%s" but %s.%s',$r->isInterface() ?'interface' :'class',$type,$message,$alternatives);
467468

468-
if ($r->isInterface()) {
469+
if ($r->isInterface() && !$alternatives) {
469470
$message .=' Did you create a class that implements this interface?';
470471
}
471472
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
useSymfony\Component\DependencyInjection\Compiler\AutowirePass;
1818
useSymfony\Component\DependencyInjection\Compiler\ResolveClassPass;
1919
useSymfony\Component\DependencyInjection\ContainerBuilder;
20+
useSymfony\Component\DependencyInjection\Exception\AutowiringFailedException;
2021
useSymfony\Component\DependencyInjection\Exception\RuntimeException;
2122
useSymfony\Component\DependencyInjection\Loader\XmlFileLoader;
2223
useSymfony\Component\DependencyInjection\Reference;
@@ -684,10 +685,6 @@ public function testIgnoreServiceWithClassNotExisting()
684685
$this->assertTrue($container->hasDefinition('bar'));
685686
}
686687

687-
/**
688-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
689-
* @expectedExceptionMessage Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".
690-
*/
691688
publicfunctiontestSetterInjectionCollisionThrowsException()
692689
{
693690
$container =newContainerBuilder();
@@ -700,7 +697,14 @@ public function testSetterInjectionCollisionThrowsException()
700697
(newAutowireRequiredMethodsPass())->process($container);
701698

702699
$pass =newAutowirePass();
703-
$pass->process($container);
700+
701+
try {
702+
$pass->process($container);
703+
}catch (AutowiringFailedException$e) {
704+
}
705+
706+
$this->assertNotNull($e);
707+
$this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".',$e->getMessage());
704708
}
705709

706710
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp