function LruMemoryCacheTest::testSetMultiple

Tests setting multiple items in the LRU memory cache.

@covers ::setMultiple

File

core/tests/Drupal/Tests/Core/Cache/LruMemoryCacheTest.php, line 160

Class

LruMemoryCacheTest
@coversDefaultClass \Drupal\Core\Cache\MemoryCache\LruMemoryCache[[api-linebreak]] @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testSetMultiple() : void {
  $lru_cache = $this->getLruMemoryCache(3);
  $lru_cache->setMultiple([
    'sparrow' => [
      'data' => 'sparrow',
    ],
    'pigeon' => [
      'data' => 'pigeon',
    ],
    'crow' => [
      'data' => 'crow',
    ],
  ]);
  $this->assertCacheData($lru_cache, [
    [
      'sparrow',
      'sparrow',
    ],
    [
      'pigeon',
      'pigeon',
    ],
    [
      'crow',
      'crow',
    ],
  ]);
  $lru_cache->setMultiple([
    'sparrow' => [
      'data' => 'sparrow2',
    ],
    'bluejay' => [
      'data' => 'bluejay',
    ],
  ]);
  $this->assertCacheData($lru_cache, [
    [
      'crow',
      'crow',
    ],
    [
      'sparrow',
      'sparrow2',
    ],
    [
      'bluejay',
      'bluejay',
    ],
  ]);
  $lru_cache->setMultiple([
    3 => [
      'data' => 'pigeon',
    ],
    2 => [
      'data' => 'eagle',
    ],
    1 => [
      'data' => 'wren',
    ],
  ]);
  $this->assertCacheData($lru_cache, [
    [
      3,
      'pigeon',
    ],
    [
      2,
      'eagle',
    ],
    [
      1,
      'wren',
    ],
  ]);
  $lru_cache->setMultiple([
    2 => [
      'data' => 'eagle2',
    ],
    4 => [
      'data' => 'cuckoo',
    ],
  ]);
  $this->assertCacheData($lru_cache, [
    [
      1,
      'wren',
    ],
    [
      2,
      'eagle2',
    ],
    [
      4,
      'cuckoo',
    ],
  ]);
}

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