function ContainerBuilderTest::testSetDefinition

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest::testSetDefinition()
  2. 10 core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest::testSetDefinition()
  3. 11.x core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest::testSetDefinition()

@covers ::setDefinition

File

core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php, line 80

Class

ContainerBuilderTest
@coversDefaultClass \Drupal\Core\DependencyInjection\ContainerBuilder @group DependencyInjection

Namespace

Drupal\Tests\Core\DependencyInjection

Code

public function testSetDefinition() {
    // Test a service with defaults.
    $container = new ContainerBuilder();
    $definition = new Definition();
    $service = $container->setDefinition('foo', $definition);
    $this->assertTrue($service->isPublic());
    $this->assertFalse($service->isPrivate());
    // Test a service with public set to false.
    $definition = new Definition();
    $definition->setPublic(FALSE);
    $service = $container->setDefinition('foo', $definition);
    $this->assertFalse($service->isPublic());
    $this->assertFalse($service->isPrivate());
    // Test a service with private set to true. Drupal does not support this.
    // We only support using setPublic() to make things not available outside
    // the container.
    $definition = new Definition();
    $definition->setPrivate(TRUE);
    $service = $container->setDefinition('foo', $definition);
    $this->assertTrue($service->isPublic());
    $this->assertFalse($service->isPrivate());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.