function ContainerTest::testGetForSerializedServiceDefinition

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGetForSerializedServiceDefinition()
  2. 8.9.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGetForSerializedServiceDefinition()
  3. 10 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGetForSerializedServiceDefinition()

Tests that Container::get() for a serialized definition works properly.

@covers ::get @covers ::createService

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 268

Class

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

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testGetForSerializedServiceDefinition() : void {
    $container_definition = $this->containerDefinition;
    $container_definition['services']['other.service'] = serialize($container_definition['services']['other.service']);
    $container = new $this->containerClass($container_definition);
    // Retrieve services of the container.
    $other_service_class = $this->containerDefinition['services']['other.service']['class'];
    $other_service = $container->get('other.service');
    $this->assertInstanceOf($other_service_class, $other_service);
    $service = $container->get('service.provider');
    $this->assertEquals($other_service, $service->getSomeOtherService(), '@other.service was injected via constructor.');
}

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