You are here

public function ContainerBuilderTest::testLazyLoadedService in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/dependency-injection/Tests/ContainerBuilderTest.php \Symfony\Component\DependencyInjection\Tests\ContainerBuilderTest::testLazyLoadedService()

File

vendor/symfony/dependency-injection/Tests/ContainerBuilderTest.php, line 814

Class

ContainerBuilderTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

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);
}