function KeyValueEntityStorageTest::testCreateWithPredefinedUuid

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

@covers ::create @covers ::doCreate

File

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

Class

KeyValueEntityStorageTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21KeyValueStore%21KeyValueEntityStorage.php/class/KeyValueEntityStorage/11.x" title="Provides a key value backend for entities." class="local">\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage</a> @group Entity

Namespace

Drupal\Tests\Core\Entity\KeyValueStore

Code

public function testCreateWithPredefinedUuid() : void {
    $this->entityType
        ->expects($this->once())
        ->method('getClass')
        ->willReturn(get_class($this->getMockEntity()));
    $this->setUpKeyValueEntityStorage();
    $hooks = [
        'test_entity_type_create',
        'entity_create',
    ];
    $this->moduleHandler
        ->expects($this->exactly(count($hooks)))
        ->method('invokeAll')
        ->with($this->callback(function (string $hook) use (&$hooks) : bool {
        return array_shift($hooks) === $hook;
    }));
    $this->uuidService
        ->expects($this->never())
        ->method('generate');
    $entity = $this->entityStorage
        ->create([
        'id' => 'foo',
        'uuid' => 'baz',
    ]);
    $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity);
    $this->assertSame('foo', $entity->id());
    $this->assertSame('baz', $entity->uuid());
}

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