merged branch fabpot/synthetic-service-fix (PR #6827)

This PR was merged into the 2.0 branch.

Commits
-------

4119caf [DependencyInjection] fixed the creation of synthetic services in ContainerBuilder

Discussion
----------

[DependencyInjection] fixed the creation of synthetic services in ContainerBuilder

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

---------------------------------------------------------------------------

by stof at 2013-01-22T00:14:29Z

👍
This commit is contained in:
Fabien Potencier 2013-01-22 08:11:41 +01:00
commit 115114b0dc
2 changed files with 15 additions and 0 deletions

View File

@ -725,6 +725,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
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));
}
if (null !== $definition->getFile()) {
require_once $this->getParameterBag()->resolveValue($definition->getFile());
}

View File

@ -315,6 +315,17 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @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
*/