You are here

public function ContainerTest::testGetForSerializedServiceDefinition in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 256
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, 'other.service has the right class.');
  $service = $container
    ->get('service.provider');
  $this
    ->assertEquals($other_service, $service
    ->getSomeOtherService(), '@other.service was injected via constructor.');
}