Skip to content

Commit 159c90d

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: Tweaking class not found autowiring error [TwigBridge] Add missing dev requirement for workflow fixed #25440 empty lines don't count for indent detection
2 parents bb50a2d + ce52d13 commit 159c90d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Compiler/AutowirePass.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\Config\Resource\ClassExistenceResource;
1415
use Symfony\Component\DependencyInjection\Config\AutowireServiceResource;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
@@ -442,7 +443,17 @@ private function createAutowiredDefinition($type)
442443
private function createTypeNotFoundMessage(TypedReference $reference, $label)
443444
{
444445
if (!$r = $this->container->getReflectionClass($type = $reference->getType(), false)) {
445-
$message = sprintf('has type "%s" but this class cannot be loaded.', $type);
446+
// either $type does not exist or a parent class does not exist
447+
try {
448+
$resource = new ClassExistenceResource($type, false);
449+
// isFresh() will explode ONLY if a parent class/trait does not exist
450+
$resource->isFresh(0);
451+
$parentMsg = false;
452+
} catch (\ReflectionException $e) {
453+
$parentMsg = $e->getMessage();
454+
}
455+
456+
$message = sprintf('has type "%s" but this class %s.', $type, $parentMsg ? sprintf('is missing a parent class (%s)', $parentMsg) : 'was not found');
446457
} else {
447458
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
448459
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));

Tests/Compiler/AutowirePassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public function testDontTriggerAutowiring()
372372

373373
/**
374374
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
375-
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.
375+
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.
376376
*/
377377
public function testClassNotFoundThrowsException()
378378
{
@@ -389,7 +389,7 @@ public function testClassNotFoundThrowsException()
389389

390390
/**
391391
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
392-
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class cannot be loaded.
392+
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).
393393
*/
394394
public function testParentClassNotFoundThrowsException()
395395
{
@@ -789,7 +789,7 @@ public function testNotWireableCalls($method, $expectedMsg)
789789
public function provideNotWireableCalls()
790790
{
791791
return array(
792-
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.'),
792+
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'),
793793
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'),
794794
array(null, 'Invalid service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
795795
);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them"
3333
},
3434
"conflict": {
35-
"symfony/config": "<3.3.1",
35+
"symfony/config": "<3.3.7",
3636
"symfony/finder": "<3.3",
3737
"symfony/proxy-manager-bridge": "<3.4",
3838
"symfony/yaml": "<3.4"

0 commit comments

Comments
 (0)