function KeyValueEntityStorageTest::testSaveDuplicate

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveDuplicate()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveDuplicate()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php \Drupal\Tests\Core\Entity\KeyValueStore\KeyValueEntityStorageTest::testSaveDuplicate()

@covers ::save @covers ::doSave

File

core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php, line 454

Class

KeyValueEntityStorageTest
@coversDefaultClass \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage @group Entity

Namespace

Drupal\Tests\Core\Entity\KeyValueStore

Code

public function testSaveDuplicate() : void {
    $this->setUpKeyValueEntityStorage();
    $entity = $this->getMockEntity(EntityBaseTest::class, [
        [
            'id' => 'foo',
        ],
    ]);
    $entity->enforceIsNew();
    $this->keyValueStore
        ->expects($this->once())
        ->method('has')
        ->willReturn(TRUE);
    $this->keyValueStore
        ->expects($this->never())
        ->method('set');
    $this->keyValueStore
        ->expects($this->never())
        ->method('delete');
    $this->expectException(EntityStorageException::class);
    $this->expectExceptionMessage("'test_entity_type' entity with ID 'foo' already exists");
    $this->entityStorage
        ->save($entity);
}

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