function EnvironmentCleaner::doCleanDatabase

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/EnvironmentCleaner.php \Drupal\Core\Test\EnvironmentCleaner::doCleanDatabase()
  2. 8.9.x core/lib/Drupal/Core/Test/EnvironmentCleaner.php \Drupal\Core\Test\EnvironmentCleaner::doCleanDatabase()
  3. 11.x core/lib/Drupal/Core/Test/EnvironmentCleaner.php \Drupal\Core\Test\EnvironmentCleaner::doCleanDatabase()

Performs the fixture database cleanup.

Return value

int The number of tables that were removed.

2 calls to EnvironmentCleaner::doCleanDatabase()
EnvironmentCleaner::cleanDatabase in core/lib/Drupal/Core/Test/EnvironmentCleaner.php
EnvironmentCleaner::cleanEnvironment in core/lib/Drupal/Core/Test/EnvironmentCleaner.php

File

core/lib/Drupal/Core/Test/EnvironmentCleaner.php, line 78

Class

EnvironmentCleaner
Helper class for cleaning test environments.

Namespace

Drupal\Core\Test

Code

protected function doCleanDatabase() : int {
    
    /** @var \Drupal\Core\Database\Schema $schema */
    $schema = $this->testDatabase
        ->schema();
    $tables = $schema->findTables('test%');
    $count = 0;
    foreach ($tables as $table) {
        // Only drop tables which begin wih 'test' followed by digits, for example,
        // {test12345678node__body}.
        if (preg_match('/^test\\d+.*/', $table, $matches)) {
            $schema->dropTable($matches[0]);
            $count++;
        }
    }
    return $count;
}

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