public function ContainerTest::test_get in Service Container 7
Same name and namespace in other branches
- 7.2 tests/src/DependencyInjection/ContainerTest.php \Drupal\Tests\service_container\DependencyInjection\ContainerTest::test_get()
Tests that Container::get() works properly. @covers ::get()
File
- tests/
src/ DependencyInjection/ ContainerTest.php, line 124 - Contains \Drupal\Tests\service_container\DependencyInjection\ContainerTest
Class
- ContainerTest
- @coversDefaultClass \Drupal\service_container\DependencyInjection\Container @group dic
Namespace
Drupal\Tests\service_container\DependencyInjectionCode
public function test_get() {
$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.');
}