function ReverseContainerTest::testRecordContainer

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/DependencyInjection/ReverseContainerTest.php \Drupal\Tests\Component\DependencyInjection\ReverseContainerTest::testRecordContainer()
  2. 10 core/tests/Drupal/Tests/Component/DependencyInjection/ReverseContainerTest.php \Drupal\Tests\Component\DependencyInjection\ReverseContainerTest::testRecordContainer()

@covers ::recordContainer

File

core/tests/Drupal/Tests/Component/DependencyInjection/ReverseContainerTest.php, line 42

Class

ReverseContainerTest
Tests the ReverseContainer class.

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testRecordContainer() : void {
    $container = new ContainerBuilder();
    $service = new \stdClass();
    $container->set('bar', $service);
    $reverse_container = new ReverseContainer($container);
    $reverse_container->recordContainer();
    $container = new ContainerBuilder();
    $reverse_container = new ReverseContainer($container);
    // New container does not have a bar service.
    $this->assertNull($reverse_container->getId($service));
    // Add the bar service to make the lookup based on the old object work as
    // expected.
    $container->set('bar', new \stdClass());
    $this->assertSame('bar', $reverse_container->getId($service));
}

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