public function XmlFileLoaderTest::testLoadAnonymousServices in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/dependency-injection/Tests/Loader/XmlFileLoaderTest.php \Symfony\Component\DependencyInjection\Tests\Loader\XmlFileLoaderTest::testLoadAnonymousServices()
File
- vendor/
symfony/ dependency-injection/ Tests/ Loader/ XmlFileLoaderTest.php, line 159
Class
Namespace
Symfony\Component\DependencyInjection\Tests\LoaderCode
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');
}