function KeyValueEntityStorageTest::testCreate

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

@covers ::create @covers ::doCreate

Return value

\Drupal\Core\Entity\EntityInterface

File

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

Class

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

Namespace

Drupal\Tests\Core\Entity\KeyValueStore

Code

public function testCreate() {
    $entity = $this->getMockEntity(EntityBaseTest::class, [], [
        'toArray',
    ]);
    $this->entityType
        ->expects($this->once())
        ->method('getClass')
        ->willReturn(get_class($entity));
    $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->once())
        ->method('generate')
        ->willReturn('bar');
    $entity = $this->entityStorage
        ->create([
        'id' => 'foo',
    ]);
    $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity);
    $this->assertSame('foo', $entity->id());
    $this->assertSame('bar', $entity->uuid());
    return $entity;
}

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