You are here

public function ContainerBuilderTest::testDefinitions 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::testDefinitions()

@covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinitions @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinitions @covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinition @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinition

File

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

Class

ContainerBuilderTest

Namespace

Symfony\Component\DependencyInjection\Tests

Code

public function testDefinitions() {
  $builder = new ContainerBuilder();
  $definitions = array(
    'foo' => new Definition('Bar\\FooClass'),
    'bar' => new Definition('BarClass'),
  );
  $builder
    ->setDefinitions($definitions);
  $this
    ->assertEquals($definitions, $builder
    ->getDefinitions(), '->setDefinitions() sets the service definitions');
  $this
    ->assertTrue($builder
    ->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
  $this
    ->assertFalse($builder
    ->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
  $builder
    ->setDefinition('foobar', $foo = new Definition('FooBarClass'));
  $this
    ->assertEquals($foo, $builder
    ->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
  $this
    ->assertTrue($builder
    ->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fluid interface by returning the service reference');
  $builder
    ->addDefinitions($defs = array(
    'foobar' => new Definition('FooBarClass'),
  ));
  $this
    ->assertEquals(array_merge($definitions, $defs), $builder
    ->getDefinitions(), '->addDefinitions() adds the service definitions');
  try {
    $builder
      ->getDefinition('baz');
    $this
      ->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
  } catch (\InvalidArgumentException $e) {
    $this
      ->assertEquals('The service definition "baz" does not exist.', $e
      ->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
  }
}