diff --git a/core/includes/database.inc b/core/includes/database.inc index 1f7dc8b7d12..7e2fe41ef10 100644 --- a/core/includes/database.inc +++ b/core/includes/database.inc @@ -721,6 +721,10 @@ function db_field_exists($table, $field) { * @see \Drupal\Core\Database\Schema::findTables() */ function db_find_tables($table_expression) { + @trigger_error( + 'db_find_tables() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use $injected_database->schema()->findTables($table_expression) instead. See https://www.drupal.org/node/2993033', + E_USER_DEPRECATED + ); return Database::getConnection()->schema()->findTables($table_expression); } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 1b603ab7364..0a9c8e524a3 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -670,7 +670,7 @@ function simpletest_clean_environment() { */ function simpletest_clean_database() { $schema = Database::getConnection()->schema(); - $tables = db_find_tables('test%'); + $tables = $schema->findTables('test%'); $count = 0; foreach ($tables as $table) { // Only drop tables which begin wih 'test' followed by digits, for example, diff --git a/core/modules/system/src/Tests/Module/ModuleTestBase.php b/core/modules/system/src/Tests/Module/ModuleTestBase.php index 257bb879cf7..30f89a34318 100644 --- a/core/modules/system/src/Tests/Module/ModuleTestBase.php +++ b/core/modules/system/src/Tests/Module/ModuleTestBase.php @@ -42,7 +42,8 @@ abstract class ModuleTestBase extends WebTestBase { * specified base table. Defaults to TRUE. */ public function assertTableCount($base_table, $count = TRUE) { - $tables = db_find_tables(Database::getConnection()->prefixTables('{' . $base_table . '}') . '%'); + $connection = Database::getConnection(); + $tables = $connection->schema()->findTables($connection->prefixTables('{' . $base_table . '}') . '%'); if ($count) { return $this->assertTrue($tables, format_string('Tables matching "@base_table" found.', ['@base_table' => $base_table])); diff --git a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php index 6cc726326dc..e48770d4995 100644 --- a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php +++ b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php @@ -39,7 +39,8 @@ abstract class ModuleTestBase extends BrowserTestBase { * specified base table. Defaults to TRUE. */ public function assertTableCount($base_table, $count = TRUE) { - $tables = db_find_tables(Database::getConnection()->prefixTables('{' . $base_table . '}') . '%'); + $connection = Database::getConnection(); + $tables = $connection->schema()->findTables($connection->prefixTables('{' . $base_table . '}') . '%'); if ($count) { return $this->assertTrue($tables, format_string('Tables matching "@base_table" found.', ['@base_table' => $base_table])); diff --git a/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php index 3c950c9be75..1724f1475d7 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php @@ -71,6 +71,19 @@ class DatabaseLegacyTest extends DatabaseTestBase { $this->assertTrue(db_table_exists('test')); } + /** + * Tests the db_find_tables() function. + * + * @expectedDeprecation db_find_tables() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use $injected_database->schema()->findTables($table_expression) instead. See https://www.drupal.org/node/2993033 + */ + public function testDbFindTables() { + $expected = [ + 'test_people' => 'test_people', + 'test_people_copy' => 'test_people_copy', + ]; + $this->assertEquals($expected, db_find_tables('test_people%')); + } + /** * Tests the db_set_active() function. *