function FileCacheTest::testGetMultiple

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php \Drupal\Tests\Component\FileCache\FileCacheTest::testGetMultiple()
  2. 10 core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php \Drupal\Tests\Component\FileCache\FileCacheTest::testGetMultiple()
  3. 11.x core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php \Drupal\Tests\Component\FileCache\FileCacheTest::testGetMultiple()

@covers ::getMultiple

File

core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php, line 69

Class

FileCacheTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21FileCache%21FileCache.php/class/FileCache/9" title="Allows to cache data based on file modification dates." class="local">\Drupal\Component\FileCache\FileCache</a> @group FileCache

Namespace

Drupal\Tests\Component\FileCache

Code

public function testGetMultiple() {
    // Test a cache miss.
    $result = $this->fileCache
        ->getMultiple([
        __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'no-llama-42.yml',
    ]);
    $this->assertEmpty($result);
    // Test a cache hit.
    $filename = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'llama-42.txt';
    $realpath = realpath($filename);
    $cid = 'prefix:test:' . $realpath;
    $data = [
        'mtime' => filemtime($realpath),
        'filepath' => $realpath,
        'data' => 42,
    ];
    $this->staticFileCache
        ->store($cid, $data);
    $result = $this->fileCache
        ->getMultiple([
        $filename,
    ]);
    $this->assertEquals([
        $filename => 42,
    ], $result);
    // Test a static cache hit.
    $file2 = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'llama-23.txt';
    $this->fileCache
        ->set($file2, 23);
    $result = $this->fileCache
        ->getMultiple([
        $filename,
        $file2,
    ]);
    $this->assertEquals([
        $filename => 42,
        $file2 => 23,
    ], $result);
    // Cleanup static caches.
    $this->fileCache
        ->delete($filename);
    $this->fileCache
        ->delete($file2);
}

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