You are here

public function DatabaseLegacyTest::testDbCreateTable in Drupal 8

Tests deprecation of the db_create_table() function.

@expectedDeprecation db_create_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call createTable() on it. For example, $injected_database->schema()->createTable($name, $table). See https://www.drupal.org/node/2993033

File

core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php, line 281

Class

DatabaseLegacyTest
Deprecation tests cases for the database layer.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testDbCreateTable() {
  $name = 'test_create_table';
  $table = [
    'fields' => [
      'id' => [
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'id',
    ],
  ];
  db_create_table($name, $table);
  $this
    ->assertTrue($this->connection
    ->schema()
    ->tableExists($name));
}