function DriverSpecificSchemaTestBase::testChangeSerialFieldLength
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Database/DriverSpecificSchemaTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificSchemaTestBase::testChangeSerialFieldLength()
Tests changing a field length.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ DriverSpecificSchemaTestBase.php, line 1319
Class
- DriverSpecificSchemaTestBase
- Tests table creation and modification via the schema API.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testChangeSerialFieldLength() : void {
$specification = [
'fields' => [
'id' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique ID.',
],
'text' => [
'type' => 'text',
'description' => 'A text field',
],
],
'primary key' => [
'id',
],
];
$this->schema
->createTable('change_serial_to_big', $specification);
// Increase the size of the field.
$new_specification = [
'size' => 'big',
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique ID.',
];
$this->schema
->changeField('change_serial_to_big', 'id', 'id', $new_specification);
$this->assertTrue($this->schema
->fieldExists('change_serial_to_big', 'id'));
// Test if we can actually add a big int.
$id = $this->connection
->insert('change_serial_to_big')
->fields([
'id' => 21474836470,
])
->execute();
$id_two = $this->connection
->insert('change_serial_to_big')
->fields([
'text' => 'Testing for ID generation',
])
->execute();
$this->assertEquals($id + 1, $id_two);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.