コード例 #1
0
 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');
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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;
 }