function SchemaUniquePrefixedKeysIndexTestBase::testChangeField

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Database/SchemaUniquePrefixedKeysIndexTestBase.php \Drupal\KernelTests\Core\Database\SchemaUniquePrefixedKeysIndexTestBase::testChangeField()

Tests changing a field to add a UNIQUE key.

File

core/tests/Drupal/KernelTests/Core/Database/SchemaUniquePrefixedKeysIndexTestBase.php, line 80

Class

SchemaUniquePrefixedKeysIndexTestBase
Tests adding UNIQUE keys to tables.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testChangeField() : void {
    $field_spec = [
        'description' => "The person's job",
        'type' => 'varchar_ascii',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
    ];
    $keys_spec = [
        'unique keys' => [
            'job' => [
                [
                    'job',
                    10,
                ],
            ],
        ],
    ];
    $this->connection
        ->schema()
        ->changeField('test_people', 'job', 'job', $field_spec, $keys_spec);
    $this->checkUniqueConstraintException('test_people', 'job');
}

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