function EntityApiTest::testUpdateWithId

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php \Drupal\KernelTests\Core\Entity\EntityApiTest::testUpdateWithId()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php \Drupal\KernelTests\Core\Entity\EntityApiTest::testUpdateWithId()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php \Drupal\KernelTests\Core\Entity\EntityApiTest::testUpdateWithId()

Tests that resaving an entity with a different entity ID throws an exception.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php, line 269

Class

EntityApiTest
Tests basic CRUD functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testUpdateWithId() {
    $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mulrev');
    // Create a new entity.
    
    /** @var \Drupal\entity_test\Entity\EntityTestMulRev $entity */
    $entity = $storage->create([
        'name' => 'revision_test',
    ]);
    $entity->save();
    $this->expectException(EntityStorageException::class);
    $this->expectExceptionMessage("Update existing 'entity_test_mulrev' entity while changing the ID is not supported.");
    $entity->id = 60;
    $entity->save();
}

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