public function ServiceDestructionTest::testDestructionUnused

Verifies that services are not unnecessarily destructed when not used.

File

drupal/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/ServiceDestructionTest.php, line 47
Contains \Drupal\system\Tests\DrupalKernel\ServiceDestructionTest.

Class

ServiceDestructionTest
Tests the service destruction functionality.

Namespace

Drupal\system\Tests\DrupalKernel

Code

public function testDestructionUnused() {

  // Enable the test module to add it to the container.
  $this
    ->enableModules(array(
    'bundle_test',
  ));

  // The service has not been destructed yet.
  $this
    ->assertNull(\Drupal::state()
    ->get('bundle_test.destructed'));

  // Terminate the kernel. The test class has not been called, so it should not
  // be destructed.
  $response = new Response();
  $this->container
    ->get('kernel')
    ->terminate($this->container
    ->get('request'), $response);
  $this
    ->assertNull(\Drupal::state()
    ->get('bundle_test.destructed'));
}