public function SchemaTest::testInvalidPrimaryKeyChange in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php \Drupal\KernelTests\Core\Database\SchemaTest::testInvalidPrimaryKeyChange()
Tests changing the primary key with an invalid field specification.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ SchemaTest.php, line 945
Class
- SchemaTest
- Tests table creation and modification via the schema API.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testInvalidPrimaryKeyChange() {
// 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 'changed_test_field' field specification does not define 'not null' as TRUE.");
$this->schema
->dropPrimaryKey($table_name);
$this->schema
->changeField($table_name, 'test_field', 'changed_test_field', [
'type' => 'int',
], [
'primary key' => [
'changed_test_field',
],
]);
}