function SqlContentEntityStorageTest::testLoadMultipleNoResult

Tests load multiple with no result.

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 1397

Class

SqlContentEntityStorageTest
Tests Drupal\Core\Entity\Sql\SqlContentEntityStorage.

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testLoadMultipleNoResult() : void {
  $this->setUpModuleHandlerNoImplementations();
  $this->entityType
    ->method('isPersistentlyCacheable')
    ->willReturn(TRUE);
  $this->entityType
    ->method('isStaticallyCacheable')
    ->willReturn(TRUE);
  $this->entityType
    ->expects($this->atLeastOnce())
    ->method('id')
    ->willReturn($this->entityTypeId);
  // Override the cache backend so we can set expectations.
  $this->cache = $this->createMock(CacheBackendInterface::class);
  // When the entity is not loaded at all, this will be recorded in the
  // static cache but not the persistent cache.
  $id = 1;
  $key = 'values:' . $this->entityTypeId . ':1';
  $this->cache
    ->expects($this->once())
    ->method('getMultiple')
    ->with([
    $key,
  ])
    ->willReturn([]);
  $this->cache
    ->expects($this->never())
    ->method('setMultiple');
  $this->entityTypeManager
    ->getActiveDefinition($this->entityType
    ->id())
    ->willReturn($this->entityType);
  $entity_storage = $this->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')
    ->setConstructorArgs([
    $this->entityType,
    $this->connection,
    $this->entityFieldManager
      ->reveal(),
    $this->cache,
    $this->languageManager,
    new MemoryCache(new Time()),
    $this->entityTypeBundleInfo,
    $this->entityTypeManager
      ->reveal(),
  ])
    ->onlyMethods([
    'getFromStorage',
    'invokeStorageLoadHook',
    'initTableLayout',
  ])
    ->getMock();
  $entity_storage->method('invokeStorageLoadHook')
    ->willReturn(NULL);
  $entity_storage->method('initTableLayout')
    ->willReturn(NULL);
  $entity_storage->expects($this->once())
    ->method('getFromStorage')
    ->with([
    $id,
  ])
    ->willReturn([]);
  // Loading the same missing entity ID twice should only result in a
  // single persistent cache get.
  $entities = $entity_storage->loadMultiple([
    $id,
  ]);
  $entities = $entity_storage->loadMultiple([
    $id,
  ]);
  $this->assertSame($entities, []);
}

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