diff --git a/ContainerBuilder.php b/ContainerBuilder.php index 0fd333aed..deb65875e 100644 --- a/ContainerBuilder.php +++ b/ContainerBuilder.php @@ -734,19 +734,22 @@ public function findDefinition($id) * * @throws RuntimeException When the scope is inactive * @throws RuntimeException When the factory definition is incomplete + * @throws RuntimeException When the service is a synthetic service * @throws InvalidArgumentException When configure callable is not callable */ private function createService(Definition $definition, $id) { + if ($definition->isSynthetic()) { + throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id)); + } + $parameterBag = $this->getParameterBag(); if (null !== $definition->getFile()) { require_once $parameterBag->resolveValue($definition->getFile()); } - $arguments = $this->resolveServices( - $parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())) - ); + $arguments = $this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments()))); if (null !== $definition->getFactoryMethod()) { if (null !== $definition->getFactoryClass()) { diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index c9e6b0784..c2677d326 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -319,6 +319,17 @@ public function testCreateServiceConfigurator() } } + /** + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService + * @expectedException \RuntimeException + */ + public function testCreateSyntheticService() + { + $builder = new ContainerBuilder(); + $builder->register('foo', 'FooClass')->setSynthetic(true); + $builder->get('foo'); + } + /** * @covers Symfony\Component\DependencyInjection\ContainerBuilder::resolveServices */