You are here

public function SchemaTest::testInvalidPrimaryKeyOnTableCreation in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php \Drupal\KernelTests\Core\Database\SchemaTest::testInvalidPrimaryKeyOnTableCreation()

Tests an invalid field specification as a primary key on table creation.

File

core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php, line 909

Class

SchemaTest
Tests table creation and modification via the schema API.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testInvalidPrimaryKeyOnTableCreation() {

  // Test making an invalid field the primary key of the table upon creation.
  $table_name = 'test_table';
  $table_spec = [
    'fields' => [
      'test_field' => [
        'type' => 'int',
      ],
    ],
    'primary key' => [
      'test_field',
    ],
  ];
  $this
    ->expectException(SchemaException::class);
  $this
    ->expectExceptionMessage("The 'test_field' field specification does not define 'not null' as TRUE.");
  $this->schema
    ->createTable($table_name, $table_spec);
}