ContainerTest.php

Same filename in this branch
  1. 8.9.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
Same filename and directory in other branches
  1. 10 core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
  2. 10 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
  3. 11.x core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
  4. 11.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
  5. 9 core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
  6. 9 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php

Namespace

Drupal\Tests\Core\DependencyInjection

File

core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php

View source
<?php

namespace Drupal\Tests\Core\DependencyInjection;

use Drupal\Core\DependencyInjection\Container;
use Drupal\Tests\UnitTestCase;
use Drupal\Tests\Core\DependencyInjection\Fixture\BarClass;

/**
 * @coversDefaultClass \Drupal\Core\DependencyInjection\Container
 * @group DependencyInjection
 */
class ContainerTest extends UnitTestCase {
  
  /**
   * Tests serialization.
   */
  public function testSerialize() {
    $container = new Container();
    $this->expectException(\AssertionError::class);
    serialize($container);
  }
  
  /**
   * @covers ::set
   */
  public function testSet() {
    $container = new Container();
    $class = new BarClass();
    $container->set('bar', $class);
    // Ensure that _serviceId is set on the object.
    $this->assertEquals('bar', $class->_serviceId);
  }

}

Classes

Title Deprecated Summary
ContainerTest @coversDefaultClass \Drupal\Core\DependencyInjection\Container[[api-linebreak]] @group DependencyInjection

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