diff --git a/core/tests/Drupal/KernelTests/Core/Database/AssertSchemaTrait.php b/core/tests/Drupal/KernelTests/Core/Database/AssertSchemaTrait.php index 20f8b04cd6..8ba2564707 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/AssertSchemaTrait.php +++ b/core/tests/Drupal/KernelTests/Core/Database/AssertSchemaTrait.php @@ -18,16 +18,17 @@ * The expected key column specifier for a table's primary key. */ protected function assertPrimaryKeyColumns($table_name, array $primary_key = []) { - $db_type = Database::getConnection()->databaseType(); + $connection = Database::getConnection(); + $db_type = $connection->databaseType(); switch ($db_type) { case 'mysql': - $result = Database::getConnection()->query("SHOW KEYS FROM {" . $table_name . "} WHERE Key_name = 'PRIMARY'")->fetchAllAssoc('Column_name'); + $result = $connection->query("SHOW KEYS FROM {" . $table_name . "} WHERE Key_name = 'PRIMARY'")->fetchAllAssoc('Column_name'); $this->assertSame($primary_key, array_keys($result)); break; case 'pgsql': - $result = Database::getConnection()->query("SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type + $result = $connection->query("SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type FROM pg_index i JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey) WHERE i.indrelid = '{" . $table_name . "}'::regclass AND i.indisprimary") @@ -40,7 +41,7 @@ protected function assertPrimaryKeyColumns($table_name, array $primary_key = []) // \Drupal\Core\Database\Driver\sqlite\Schema::introspectSchema() method // because we have no other way of getting the table prefixes needed for // running a straight PRAGMA query. - $schema_object = Database::getConnection()->schema(); + $schema_object = $connection->schema(); $reflection = new \ReflectionMethod($schema_object, 'introspectSchema'); $reflection->setAccessible(TRUE);