You are here

public function ContainerTest::testGet in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/dependency-injection/Tests/ContainerTest.php \Symfony\Component\DependencyInjection\Tests\ContainerTest::testGet()
  2. 8.0 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGet()
Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGet()

Tests that Container::get() works properly.

@covers ::get @covers ::createService

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 148
Contains \Drupal\Tests\Component\DependencyInjection\ContainerTest.

Class

ContainerTest
@coversDefaultClass \Drupal\Component\DependencyInjection\Container @group DependencyInjection

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testGet() {
  $container = $this->container
    ->get('service_container');
  $this
    ->assertSame($this->container, $container, 'Container can be retrieved from itself.');

  // Retrieve services of the container.
  $other_service_class = $this->containerDefinition['services']['other.service']['class'];
  $other_service = $this->container
    ->get('other.service');
  $this
    ->assertInstanceOf($other_service_class, $other_service, 'other.service has the right class.');
  $some_parameter = $this->containerDefinition['parameters']['some_config'];
  $some_other_parameter = $this->containerDefinition['parameters']['some_other_config'];
  $service = $this->container
    ->get('service.provider');
  $this
    ->assertEquals($other_service, $service
    ->getSomeOtherService(), '@other.service was injected via constructor.');
  $this
    ->assertEquals($some_parameter, $service
    ->getSomeParameter(), '%some_config% was injected via constructor.');
  $this
    ->assertEquals($this->container, $service
    ->getContainer(), 'Container was injected via setter injection.');
  $this
    ->assertEquals($some_other_parameter, $service
    ->getSomeOtherParameter(), '%some_other_config% was injected via setter injection.');
  $this
    ->assertEquals($service->_someProperty, 'foo', 'Service has added properties.');
}