public function testLoad() { $loader = new ClosureLoader($container = new ContainerBuilder()); $loader->load(function ($container) { $container->setParameter('foo', 'foo'); }); $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a \\Closure resource'); }
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); }
protected function createContainerFromClosure($closure, $data = array()) { $container = $this->createContainer($data); $container->registerExtension(new FrameworkExtension()); $loader = new ClosureLoader($container); $loader->load($closure); $container->getCompilerPassConfig()->setOptimizationPasses(array()); $container->getCompilerPassConfig()->setRemovingPasses(array()); $container->compile(); return $container; }