Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcb1441

Browse files
committed
[DependencyInjection] added a test for the previous merge (refs #7261)
1 parent 71cba81 commit dcb1441

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\ContainerInterface;
2121
use Symfony\Component\DependencyInjection\Definition;
22+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2223
use Symfony\Component\DependencyInjection\Reference;
2324
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2425
use Symfony\Component\Config\Resource\FileResource;
@@ -116,6 +117,26 @@ public function testGet()
116117
$this->assertTrue($builder->get('bar') === $builder->get('bar'), '->get() always returns the same instance if the service is shared');
117118
}
118119

120+
/**
121+
* @covers \Symfony\Component\DependencyInjection\ContainerBuilder::get
122+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
123+
* @expectedExceptionMessage You have requested a synthetic service ("foo"). The DIC does not know how to construct this service.
124+
*/
125+
public function testGetXXX()
126+
{
127+
$builder = new ContainerBuilder();
128+
$builder->register('foo', 'stdClass')->setSynthetic(true);
129+
130+
// we expect a RuntimeException here as foo is synthetic
131+
try {
132+
$builder->get('foo');
133+
} catch (RuntimeException $e) {
134+
}
135+
136+
// we must also have the same RuntimeException here
137+
$builder->get('foo');
138+
}
139+
119140
/**
120141
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getServiceIds
121142
*/

0 commit comments

Comments
 (0)