You are here

public function ContainerTest::testGetForSerializedServiceDefinition in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGetForSerializedServiceDefinition()
  2. 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
Contains \Drupal\Tests\Component\DependencyInjection\ContainerTest.

Class

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

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testGetForSerializedServiceDefinition() {
  $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.');
}