Fixing bad type-hint auto-wiring bug
This commit is contained in:
parent
7beea17a02
commit
b7b182ea9e
@ -104,7 +104,7 @@ class AutowirePass implements CompilerPassInterface
|
|||||||
// Typehint against a non-existing class
|
// Typehint against a non-existing class
|
||||||
|
|
||||||
if (!$parameter->isDefaultValueAvailable()) {
|
if (!$parameter->isDefaultValueAvailable()) {
|
||||||
continue;
|
throw new RuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $reflectionException->getMessage()), 0, $reflectionException);
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $parameter->getDefaultValue();
|
$value = $parameter->getDefaultValue();
|
||||||
|
@ -201,6 +201,21 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertCount(0, $container->getDefinition('bar')->getArguments());
|
$this->assertCount(0, $container->getDefinition('bar')->getArguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||||
|
* @expectedExceptionMessage Cannot autowire argument 2 for Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument because the type-hinted class does not exist (Class Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass does not exist).
|
||||||
|
*/
|
||||||
|
public function testClassNotFoundThrowsException()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$aDefinition = $container->register('a', __NAMESPACE__.'\BadTypeHintedArgument');
|
||||||
|
$aDefinition->setAutowired(true);
|
||||||
|
|
||||||
|
$pass = new AutowirePass();
|
||||||
|
$pass->process($container);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
@ -298,3 +313,10 @@ class OptionalParameter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BadTypeHintedArgument
|
||||||
|
{
|
||||||
|
public function __construct(Dunglas $k, NotARealClass $r)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user