public function XmlFileLoaderTest::testLoadServices

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php, line 164

Class

XmlFileLoaderTest

Namespace

Symfony\Component\DependencyInjection\Tests\Loader

Code

public function testLoadServices() {
  $container = new ContainerBuilder();
  $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath . '/xml'));
  $loader
    ->load('services6.xml');
  $services = $container
    ->getDefinitions();
  $this
    ->assertTrue(isset($services['foo']), '->load() parses <service> elements');
  $this
    ->assertEquals('Symfony\\Component\\DependencyInjection\\Definition', get_class($services['foo']), '->load() converts <service> element to Definition instances');
  $this
    ->assertEquals('FooClass', $services['foo']
    ->getClass(), '->load() parses the class attribute');
  $this
    ->assertEquals('container', $services['scope.container']
    ->getScope());
  $this
    ->assertEquals('custom', $services['scope.custom']
    ->getScope());
  $this
    ->assertEquals('prototype', $services['scope.prototype']
    ->getScope());
  $this
    ->assertEquals('getInstance', $services['constructor']
    ->getFactoryMethod(), '->load() parses the factory-method attribute');
  $this
    ->assertEquals('%path%/foo.php', $services['file']
    ->getFile(), '->load() parses the file tag');
  $this
    ->assertEquals(array(
    'foo',
    new Reference('foo'),
    array(
      true,
      false,
    ),
  ), $services['arguments']
    ->getArguments(), '->load() parses the argument tags');
  $this
    ->assertEquals('sc_configure', $services['configurator1']
    ->getConfigurator(), '->load() parses the configurator tag');
  $this
    ->assertEquals(array(
    new Reference('baz', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false),
    'configure',
  ), $services['configurator2']
    ->getConfigurator(), '->load() parses the configurator tag');
  $this
    ->assertEquals(array(
    'BazClass',
    'configureStatic',
  ), $services['configurator3']
    ->getConfigurator(), '->load() parses the configurator tag');
  $this
    ->assertEquals(array(
    array(
      'setBar',
      array(),
    ),
  ), $services['method_call1']
    ->getMethodCalls(), '->load() parses the method_call tag');
  $this
    ->assertEquals(array(
    array(
      'setBar',
      array(
        'foo',
        new Reference('foo'),
        array(
          true,
          false,
        ),
      ),
    ),
  ), $services['method_call2']
    ->getMethodCalls(), '->load() parses the method_call tag');
  $this
    ->assertNull($services['factory_service']
    ->getClass());
  $this
    ->assertEquals('getInstance', $services['factory_service']
    ->getFactoryMethod());
  $this
    ->assertEquals('baz_factory', $services['factory_service']
    ->getFactoryService());
  $this
    ->assertTrue($services['request']
    ->isSynthetic(), '->load() parses the synthetic flag');
  $this
    ->assertTrue($services['request']
    ->isSynchronized(), '->load() parses the synchronized flag');
  $this
    ->assertTrue($services['request']
    ->isLazy(), '->load() parses the lazy flag');
  $aliases = $container
    ->getAliases();
  $this
    ->assertTrue(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
  $this
    ->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
  $this
    ->assertTrue($aliases['alias_for_foo']
    ->isPublic());
  $this
    ->assertTrue(isset($aliases['another_alias_for_foo']));
  $this
    ->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
  $this
    ->assertFalse($aliases['another_alias_for_foo']
    ->isPublic());
}