DecoratedServiceTest.php

Same filename and directory in other branches
  1. 9 core/modules/system/tests/src/Kernel/DecoratedServiceTest.php
  2. 11.x core/modules/system/tests/src/Kernel/DecoratedServiceTest.php

Namespace

Drupal\Tests\system\Kernel

File

core/modules/system/tests/src/Kernel/DecoratedServiceTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\system\Kernel;

use Drupal\Component\DependencyInjection\ReverseContainer;
use Drupal\decorated_service_test\TestServiceDecorator;
use Drupal\KernelTests\KernelTestBase;

/**
 * Test handling of decorated services in DependencySerializationTraitPass.
 *
 * @group system
 */
class DecoratedServiceTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'decorated_service_test',
  ];
  
  /**
   * Check that decorated services keep their original service ID.
   */
  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);
  }

}

Classes

Title Deprecated Summary
DecoratedServiceTest Test handling of decorated services in DependencySerializationTraitPass.

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