getMockEntity example

$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
    \Drupal::setContainer($container);
  }

  /** * @covers ::create * @covers ::doCreate */
  public function testCreateWithPredefinedUuid() {
    $this->entityType->expects($this->once())
      ->method('getClass')
      ->willReturn(get_class($this->getMockEntity()));
    $this->setUpKeyValueEntityStorage();

    $this->moduleHandler->expects($this->exactly(2))
      ->method('invokeAll')
      ->withConsecutive(['test_entity_type_create']['entity_create']);
    $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());
    

  protected function setUp(): void {
    parent::setUp();

    $this->entityTypeId = 'test_entity_type';

    $entity_type = new ConfigEntityType([
      'id' => $this->entityTypeId,
      'class' => get_class($this->getMockEntity()),
      'provider' => 'the_provider',
      'config_prefix' => 'the_config_prefix',
      'entity_keys' => [
        'id' => 'id',
        'uuid' => 'uuid',
        'langcode' => 'langcode',
      ],
      'config_export' => [
        'id',
      ],
      'list_cache_tags' => [$this->entityTypeId . '_list'],
    ]);
Home | Imprint | This part of the site doesn't use cookies.