You are here

public function XmlFileLoaderTest::testLoadAnonymousServices in Service Container 7

Same name and namespace in other branches
  1. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php \Symfony\Component\DependencyInjection\Tests\Loader\XmlFileLoaderTest::testLoadAnonymousServices()

File

modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php, line 159

Class

XmlFileLoaderTest

Namespace

Symfony\Component\DependencyInjection\Tests\Loader

Code

public function testLoadAnonymousServices() {
  $container = new ContainerBuilder();
  $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath . '/xml'));
  $loader
    ->load('services5.xml');
  $services = $container
    ->getDefinitions();
  $this
    ->assertCount(4, $services, '->load() attributes unique ids to anonymous services');

  // anonymous service as an argument
  $args = $services['foo']
    ->getArguments();
  $this
    ->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
  $this
    ->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
  $this
    ->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
  $inner = $services[(string) $args[0]];
  $this
    ->assertEquals('BarClass', $inner
    ->getClass(), '->load() uses the same configuration as for the anonymous ones');

  // inner anonymous services
  $args = $inner
    ->getArguments();
  $this
    ->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
  $this
    ->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
  $this
    ->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
  $inner = $services[(string) $args[0]];
  $this
    ->assertEquals('BazClass', $inner
    ->getClass(), '->load() uses the same configuration as for the anonymous ones');
  $this
    ->assertFalse($inner
    ->isPublic());

  // anonymous service as a property
  $properties = $services['foo']
    ->getProperties();
  $property = $properties['p'];
  $this
    ->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
  $this
    ->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
  $inner = $services[(string) $property];
  $this
    ->assertEquals('BazClass', $inner
    ->getClass(), '->load() uses the same configuration as for the anonymous ones');
}