public function ContainerBuilderTest::testLazyLoadedService in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php \Symfony\Component\DependencyInjection\Tests\ContainerBuilderTest::testLazyLoadedService()
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Tests/ ContainerBuilderTest.php, line 819
Class
Namespace
Symfony\Component\DependencyInjection\TestsCode
public function testLazyLoadedService() {
$loader = new ClosureLoader($container = new ContainerBuilder());
$loader
->load(function (ContainerBuilder $container) {
$container
->set('a', new \BazClass());
$definition = new Definition('BazClass');
$definition
->setLazy(true);
$container
->setDefinition('a', $definition);
});
$container
->setResourceTracking(true);
$container
->compile();
$class = new \BazClass();
$reflectionClass = new \ReflectionClass($class);
$r = new \ReflectionProperty($container, 'resources');
$r
->setAccessible(true);
$resources = $r
->getValue($container);
$classInList = false;
foreach ($resources as $resource) {
if ($resource
->getResource() === $reflectionClass
->getFileName()) {
$classInList = true;
break;
}
}
$this
->assertTrue($classInList);
}