Skip to content

Commit f8674cf

Browse files
Merge branch '3.4' into 4.0
* 3.4: Clean up Update return type in docblock. PHP CS Fixer: no need to exclude xml and yml files PHP CS Fixer: no need to exclude json file Update LICENSE year... forever fixed some deprecation messages fixed CS Fixes for Oracle in PdoSessionHandler fixed some deprecation messages fixed some deprecation messages fixed some deprecation messages fixed some deprecation messages [TwigBundle/Brige] catch missing requirements to throw meaningful exceptions [HttpKernel] Call Response->setPrivate() instead of sending raw header() when session is started [FrameworkBundle] Make cache:clear "atomic" and consistent with cache:warmup Suggest to write an implementation if the interface cannot be autowired [Debug] Skip DebugClassLoader checks for already parsed files [2.7][DX] Use constant message contextualisation for deprecations Remove group options without data and fix normalization Remove redundant translation path
2 parents b76c15b + 2081fa2 commit f8674cf

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

Compiler/AutowirePass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ private function createTypeNotFoundMessage(TypedReference $reference, $label)
329329
} else {
330330
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
331331
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));
332+
333+
if ($r->isInterface()) {
334+
$message .= ' Did you create a class that implements this interface?';
335+
}
332336
}
333337

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

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2004-2017 Fabien Potencier
1+
Copyright (c) 2004-present Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Tests/Compiler/AutowirePassTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,23 @@ public function testSetterInjectionCollisionThrowsException()
595595
$pass->process($container);
596596
}
597597

598+
/**
599+
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
600+
* @expectedExceptionMessage Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface?
601+
*/
602+
public function testInterfaceWithNoImplementationSuggestToWriteOne()
603+
{
604+
$container = new ContainerBuilder();
605+
606+
$aDefinition = $container->register('my_service', K::class);
607+
$aDefinition->setAutowired(true);
608+
609+
(new AutowireRequiredMethodsPass())->process($container);
610+
611+
$pass = new AutowirePass();
612+
$pass->process($container);
613+
}
614+
598615
/**
599616
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
600617
* @expectedExceptionMessage Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.

Tests/Fixtures/includes/autowiring_classes.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public function __construct(I $i)
9090
}
9191
}
9292

93+
class K
94+
{
95+
public function __construct(IInterface $i)
96+
{
97+
}
98+
}
99+
93100
interface CollisionInterface
94101
{
95102
}

0 commit comments

Comments
 (0)