public function ServiceDestructionTest::testDestructionUsed

Verifies that services are destructed when used.

File

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

Class

ServiceDestructionTest
Tests the service destruction functionality.

Namespace

Drupal\system\Tests\DrupalKernel

Code

public function testDestructionUsed() {

  // 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'));

  // Call the class and then terminate the kernel
  $this->container
    ->get('bundle_test_class');
  $response = new Response();
  $this->container
    ->get('kernel')
    ->terminate($this->container
    ->get('request'), $response);
  $this
    ->assertTrue(\Drupal::state()
    ->get('bundle_test.destructed'));
}