function FileCacheTest::testGet

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

@covers ::get @covers ::__construct

File

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

Class

FileCacheTest
@coversDefaultClass \Drupal\Component\FileCache\FileCache @group FileCache

Namespace

Drupal\Tests\Component\FileCache

Code

public function testGet() : void {
    // Test a cache miss.
    $result = $this->fileCache
        ->get(__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'no-llama-42.yml');
    $this->assertNull($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
        ->get($filename);
    $this->assertEquals(42, $result);
    // Cleanup static caches.
    $this->fileCache
        ->delete($filename);
}

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