Fixing bad type-hint auto-wiring bug

This commit is contained in:
Ryan Weaver 2015-11-04 13:04:11 -05:00 committed by Fabien Potencier
parent 7beea17a02
commit b7b182ea9e
2 changed files with 23 additions and 1 deletions

View File

@ -104,7 +104,7 @@ class AutowirePass implements CompilerPassInterface
// Typehint against a non-existing class
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();

View File

@ -201,6 +201,21 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
$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
@ -298,3 +313,10 @@ class OptionalParameter
{
}
}
class BadTypeHintedArgument
{
public function __construct(Dunglas $k, NotARealClass $r)
{
}
}