function SchemaTest::testInvalidPrimaryKeyAddition

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

Tests adding an invalid field specification as a primary key.

File

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

Class

SchemaTest
Tests table creation and modification via the schema API.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testInvalidPrimaryKeyAddition() {
    // Test adding a new invalid field to the primary key.
    $table_name = 'test_table';
    $table_spec = [
        'fields' => [
            'test_field' => [
                'type' => 'int',
                'not null' => TRUE,
            ],
        ],
        'primary key' => [
            'test_field',
        ],
    ];
    $this->schema
        ->createTable($table_name, $table_spec);
    $this->expectException(SchemaException::class);
    $this->expectExceptionMessage("The 'new_test_field' field specification does not define 'not null' as TRUE.");
    $this->schema
        ->addField($table_name, 'new_test_field', [
        'type' => 'int',
    ], [
        'primary key' => [
            'test_field',
            'new_test_field',
        ],
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.