function FieldStorageCrudTest::testUpdateFieldType

Same name and namespace in other branches
  1. 10 core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testUpdateFieldType()
  2. 9 core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testUpdateFieldType()
  3. 8.9.x core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testUpdateFieldType()

Tests that updating a field storage type is not allowed.

File

core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php, line 396

Class

FieldStorageCrudTest
Tests field storage create, read, update, and delete.

Namespace

Drupal\Tests\field\Kernel

Code

public function testUpdateFieldType() : void {
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'field_type',
    'entity_type' => 'entity_test',
    'type' => 'decimal',
  ]);
  $field_storage->save();
  try {
    $field_storage->set('type', 'integer');
    $field_storage->save();
    $this->fail('Cannot update a field to a different type.');
  } catch (\Exception $e) {
    $this->assertInstanceOf(FieldException::class, $e);
  }
}

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