You are here

public function ContainerBuilderTest::testMerge in Zircon Profile 8

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

@covers Symfony\Component\DependencyInjection\ContainerBuilder::merge

File

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

Class

ContainerBuilderTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

public function testMerge() {
  $container = new ContainerBuilder(new ParameterBag(array(
    'bar' => 'foo',
  )));
  $container
    ->setResourceTracking(false);
  $config = new ContainerBuilder(new ParameterBag(array(
    'foo' => 'bar',
  )));
  $container
    ->merge($config);
  $this
    ->assertEquals(array(
    'bar' => 'foo',
    'foo' => 'bar',
  ), $container
    ->getParameterBag()
    ->all(), '->merge() merges current parameters with the loaded ones');
  $container = new ContainerBuilder(new ParameterBag(array(
    'bar' => 'foo',
  )));
  $container
    ->setResourceTracking(false);
  $config = new ContainerBuilder(new ParameterBag(array(
    'foo' => '%bar%',
  )));
  $container
    ->merge($config);
  $container
    ->compile();
  $this
    ->assertEquals(array(
    'bar' => 'foo',
    'foo' => 'foo',
  ), $container
    ->getParameterBag()
    ->all(), '->merge() evaluates the values of the parameters towards already defined ones');
  $container = new ContainerBuilder(new ParameterBag(array(
    'bar' => 'foo',
  )));
  $container
    ->setResourceTracking(false);
  $config = new ContainerBuilder(new ParameterBag(array(
    'foo' => '%bar%',
    'baz' => '%foo%',
  )));
  $container
    ->merge($config);
  $container
    ->compile();
  $this
    ->assertEquals(array(
    'bar' => 'foo',
    'foo' => 'foo',
    'baz' => 'foo',
  ), $container
    ->getParameterBag()
    ->all(), '->merge() evaluates the values of the parameters towards already defined ones');
  $container = new ContainerBuilder();
  $container
    ->setResourceTracking(false);
  $container
    ->register('foo', 'Bar\\FooClass');
  $container
    ->register('bar', 'BarClass');
  $config = new ContainerBuilder();
  $config
    ->setDefinition('baz', new Definition('BazClass'));
  $config
    ->setAlias('alias_for_foo', 'foo');
  $container
    ->merge($config);
  $this
    ->assertEquals(array(
    'foo',
    'bar',
    'baz',
  ), array_keys($container
    ->getDefinitions()), '->merge() merges definitions already defined ones');
  $aliases = $container
    ->getAliases();
  $this
    ->assertTrue(isset($aliases['alias_for_foo']));
  $this
    ->assertEquals('foo', (string) $aliases['alias_for_foo']);
  $container = new ContainerBuilder();
  $container
    ->setResourceTracking(false);
  $container
    ->register('foo', 'Bar\\FooClass');
  $config
    ->setDefinition('foo', new Definition('BazClass'));
  $container
    ->merge($config);
  $this
    ->assertEquals('BazClass', $container
    ->getDefinition('foo')
    ->getClass(), '->merge() overrides already defined services');
}