function DecoratedServiceTest::testDecoratedServiceId

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/DecoratedServiceTest.php \Drupal\Tests\system\Kernel\DecoratedServiceTest::testDecoratedServiceId()
  2. 10 core/modules/system/tests/src/Kernel/DecoratedServiceTest.php \Drupal\Tests\system\Kernel\DecoratedServiceTest::testDecoratedServiceId()

Check that decorated services keep their original service ID.

File

core/modules/system/tests/src/Kernel/DecoratedServiceTest.php, line 25

Class

DecoratedServiceTest
Test handling of decorated services with the reverse container.

Namespace

Drupal\Tests\system\Kernel

Code

public function testDecoratedServiceId() : void {
    // Service decorated once.
    $test_service = $this->container
        ->get('test_service');
    $this->assertEquals('test_service', $this->container
        ->get(ReverseContainer::class)
        ->getId($test_service));
    $this->assertInstanceOf(TestServiceDecorator::class, $test_service);
    // Service decorated twice.
    $test_service2 = $this->container
        ->get('test_service2');
    $this->assertEquals('test_service2', $this->container
        ->get(ReverseContainer::class)
        ->getId($test_service2));
    $this->assertInstanceOf(TestServiceDecorator::class, $test_service2);
}

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