function SchemaUniquePrefixedKeysIndexTestBase::testCreateTable

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Database/SchemaUniquePrefixedKeysIndexTestBase.php \Drupal\KernelTests\Core\Database\SchemaUniquePrefixedKeysIndexTestBase::testCreateTable()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/SchemaUniquePrefixedKeysIndexTestBase.php \Drupal\KernelTests\Core\Database\SchemaUniquePrefixedKeysIndexTestBase::testCreateTable()

Tests UNIQUE keys put directly on the table definition.

Attributes

#[IgnoreDeprecations]

File

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

Class

SchemaUniquePrefixedKeysIndexTestBase
Tests adding UNIQUE keys to tables.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testCreateTable() : void {
  $this->expectUserDeprecationMessage('Specification of unique keys with column length is deprecated in drupal:12.1.0 and will throw a SchemaException from drupal:13.0.0. Specify full columns for an unique key, or use an index for columns with partial length. See https://www.drupal.org/node/3375071');
  $this->connection
    ->schema()
    ->createTable('test_unique', [
    'fields' => [
      'field' => [
        'type' => 'varchar',
        'length' => 50,
      ],
    ],
    'unique keys' => [
      'field' => [
        [
          'field',
          10,
        ],
      ],
    ],
  ]);
  $this->checkUniqueConstraintException('test_unique', 'field');
}

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