You are here

protected function KernelTestBase::tearDown in Zircon Profile 8

Same name in this branch
  1. 8 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::tearDown()
  2. 8 core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::tearDown()
Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::tearDown()
2 calls to KernelTestBase::tearDown()
DrupalSetMessageTest::tearDown in core/tests/Drupal/KernelTests/Core/Common/DrupalSetMessageTest.php
KernelTestBaseTest::tearDown in core/tests/Drupal/KernelTests/KernelTestBaseTest.php
2 methods override KernelTestBase::tearDown()
DrupalSetMessageTest::tearDown in core/tests/Drupal/KernelTests/Core/Common/DrupalSetMessageTest.php
KernelTestBaseTest::tearDown in core/tests/Drupal/KernelTests/KernelTestBaseTest.php

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 627
Contains \Drupal\KernelTests\KernelTestBase.

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function tearDown() {

  // 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']['default'];
  $test_connection_info = Database::getConnectionInfo('default');
  $test_prefix = $test_connection_info['default']['prefix']['default'];
  if ($original_prefix != $test_prefix) {
    $tables = Database::getConnection()
      ->schema()
      ->findTables('%');
    foreach ($tables as $table) {
      if (Database::getConnection()
        ->schema()
        ->dropTable($table)) {
        unset($tables[$table]);
      }
    }
  }

  // Free up memory: Own properties.
  $this->classLoader = NULL;
  $this->vfsRoot = NULL;
  $this->configImporter = NULL;

  // Free up memory: Custom test class properties.
  // Note: Private properties cannot be cleaned up.
  $rc = new \ReflectionClass(__CLASS__);
  $blacklist = array();
  foreach ($rc
    ->getProperties() as $property) {
    $blacklist[$property->name] = $property
      ->getDeclaringClass()->name;
  }
  $rc = new \ReflectionClass($this);
  foreach ($rc
    ->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $property) {
    if (!$property
      ->isStatic() && !isset($blacklist[$property->name])) {
      $this->{$property->name} = 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(array());
  parent::tearDown();
}