File
- drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php, line 119
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
->assertEquals(4, count($services), '->load() attributes unique ids to anonymous services');
$args = $services['foo']
->getArguments();
$this
->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
$this
->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($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');
$args = $inner
->getArguments();
$this
->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
$this
->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($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');
$properties = $services['foo']
->getProperties();
$property = $properties['p'];
$this
->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($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');
}