function ContainerTest::testReset

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testReset()

Tests Container::reset().

@covers ::reset

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 718

Class

ContainerTest
@coversDefaultClass \Drupal\Component\DependencyInjection\Container @group DependencyInjection

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testReset() : void {
    $this->assertFalse($this->container
        ->initialized('late.service'), 'Late service is not initialized.');
    $this->container
        ->get('late.service');
    $this->assertTrue($this->container
        ->initialized('late.service'), 'Late service is initialized after it was retrieved once.');
    // Reset the container. All initialized services will be reset.
    $this->container
        ->reset();
    $this->assertFalse($this->container
        ->initialized('late.service'), 'Late service is not initialized.');
    $this->container
        ->get('late.service');
    $this->assertTrue($this->container
        ->initialized('late.service'), 'Late service is initialized after it was retrieved once.');
    $this->assertSame($this->container, $this->container
        ->get('service_container'));
}

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