public function ContainerTest::testGet in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGet()
- 10 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 150 - Contains \Drupal\Tests\Component\DependencyInjection\ContainerTest.
Class
- ContainerTest
- @coversDefaultClass \Drupal\Component\DependencyInjection\Container @group DependencyInjection
Namespace
Drupal\Tests\Component\DependencyInjectionCode
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);
$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.');
}