From dcb1441d23fcd4d51608deaab0f4d484cd80e20b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 6 Mar 2013 17:38:10 +0100 Subject: [PATCH] [DependencyInjection] added a test for the previous merge (refs #7261) --- .../Tests/ContainerBuilderTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index c2677d326c..48dd10acf5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -19,6 +19,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\Config\Resource\FileResource; @@ -116,6 +117,26 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase $this->assertTrue($builder->get('bar') === $builder->get('bar'), '->get() always returns the same instance if the service is shared'); } + /** + * @covers \Symfony\Component\DependencyInjection\ContainerBuilder::get + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @expectedExceptionMessage You have requested a synthetic service ("foo"). The DIC does not know how to construct this service. + */ + public function testGetXXX() + { + $builder = new ContainerBuilder(); + $builder->register('foo', 'stdClass')->setSynthetic(true); + + // we expect a RuntimeException here as foo is synthetic + try { + $builder->get('foo'); + } catch (RuntimeException $e) { + } + + // we must also have the same RuntimeException here + $builder->get('foo'); + } + /** * @covers Symfony\Component\DependencyInjection\ContainerBuilder::getServiceIds */