You are here

protected function DatabaseTestsTrait::assertNotHasPrimaryKey in Search API 8

Asserts that the given table exists and does not have a primary key.

Parameters

string $table: The name of the table.

string|null $message: (optional) The message to print for the assertion, or NULL to use an automatically generated one.

1 call to DatabaseTestsTrait::assertNotHasPrimaryKey()
SearchApiDbUpdate8102Test::testUpdate8102 in modules/search_api_db/src/Tests/Update/SearchApiDbUpdate8102Test.php
Tests whether search_api_db_update_8102() works correctly.

File

modules/search_api_db/src/Tests/DatabaseTestsTrait.php, line 54

Class

DatabaseTestsTrait
Provides some common helper methods for database tests.

Namespace

Drupal\search_api_db\Tests

Code

protected function assertNotHasPrimaryKey($table, $message = NULL) {
  $schema = \Drupal::database()
    ->schema();
  $this
    ->assertTrue($schema
    ->tableExists($table), "Table {$table} exists.");
  if (!$message) {
    $message = "Table {$table} does not have a primary key.";
  }

  // The database layer doesn't support generic introspection into primary
  // keys. The simplest way to make sure a table does not have a primary key
  // is trying to drop it and checking the return value.
  $this
    ->assertFalse($schema
    ->dropPrimaryKey($table), $message);
}