function KernelTestBase::tearDown

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::tearDown()
  2. 10 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::tearDown()
  3. 8.9.x core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::tearDown()
  4. 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::tearDown()
10 calls to KernelTestBase::tearDown()
DrupalKernelTest::tearDown in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
FileDeleteRecursiveTest::tearDown in core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php
GenericCacheBackendUnitTestBase::tearDown in core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
JsonApiTopLevelResourceNormalizerTest::tearDown in core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php
KernelTestBaseTest::tearDown in core/tests/Drupal/KernelTests/KernelTestBaseTest.php

... See full list

9 methods override KernelTestBase::tearDown()
DrupalKernelTest::tearDown in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
FileDeleteRecursiveTest::tearDown in core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php
GenericCacheBackendUnitTestBase::tearDown in core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
JsonApiTopLevelResourceNormalizerTest::tearDown in core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php
KernelTestBaseTest::tearDown in core/tests/Drupal/KernelTests/KernelTestBaseTest.php

... See full list

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 649

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function tearDown() : void {
  if ($this->container) {
    // Clean up mock session started in DrupalKernel::preHandle().
    /** @var \Symfony\Component\HttpFoundation\Session\Session $session */
    $session = $this->container
      ->get('request_stack')
      ->getSession();
    $session->clear();
    $session->save();
  }
  // Destroy the testing kernel.
  if (isset($this->kernel)) {
    $this->kernel
      ->shutdown();
  }
  // Remove all prefixed tables.
  $original_connection_info = Database::getConnectionInfo('simpletest_original_default');
  $original_prefix = $original_connection_info['default']['prefix'] ?? NULL;
  $test_connection_info = Database::getConnectionInfo('default');
  $test_prefix = $test_connection_info['default']['prefix'] ?? NULL;
  if ($original_prefix != $test_prefix) {
    $tables = Database::getConnection()->schema()
      ->findTables('%');
    foreach ($tables as $table) {
      if (Database::getConnection()->schema()
        ->dropTable($table)) {
        unset($tables[$table]);
      }
    }
  }
  // If the test used the regular file system, remove any files created.
  if (!str_starts_with($this->siteDirectory, 'vfs://')) {
    // Delete test site directory.
    $callback = function (string $path) {
      @chmod($path, 0700);
    };
    \Drupal::service('file_system')->deleteRecursive($this->siteDirectory, $callback);
  }
  // Free up memory: Own properties.
  $this->classLoader = NULL;
  $this->vfsRoot = NULL;
  $this->configImporter = NULL;
  // Clean FileCache cache.
  FileCache::reset();
  // Clean up statics, container, and settings.
  if (function_exists('drupal_static_reset')) {
    drupal_static_reset();
  }
  \Drupal::unsetContainer();
  $this->container = NULL;
  new Settings([]);
  parent::tearDown();
}

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