ServiceDestructionTest.php in Drupal 8
File
core/tests/Drupal/KernelTests/Core/DrupalKernel/ServiceDestructionTest.php
View source
<?php
namespace Drupal\KernelTests\Core\DrupalKernel;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Response;
class ServiceDestructionTest extends KernelTestBase {
public function testDestructionUsed() {
$this
->enableModules([
'service_provider_test',
]);
$request = $this->container
->get('request_stack')
->getCurrentRequest();
$kernel = $this->container
->get('kernel');
$kernel
->preHandle($request);
$this
->assertNull(\Drupal::state()
->get('service_provider_test.destructed'));
$this->container
->get('service_provider_test_class');
$response = new Response();
$kernel
->terminate($request, $response);
$this
->assertTrue(\Drupal::state()
->get('service_provider_test.destructed'));
}
public function testDestructionUnused() {
$this
->enableModules([
'service_provider_test',
]);
$request = $this->container
->get('request_stack')
->getCurrentRequest();
$kernel = $this->container
->get('kernel');
$kernel
->preHandle($request);
$this
->assertNull(\Drupal::state()
->get('service_provider_test.destructed'));
$response = new Response();
$kernel
->terminate($request, $response);
$this
->assertNull(\Drupal::state()
->get('service_provider_test.destructed'));
}
}