function ChainedFastBackendTest::testGetDoesNotHitConsistentBackend

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testGetDoesNotHitConsistentBackend()
  2. 10 core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testGetDoesNotHitConsistentBackend()
  3. 11.x core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testGetDoesNotHitConsistentBackend()

Tests a get() on the fast backend, with no hit on the consistent backend.

File

core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php, line 39

Class

ChainedFastBackendTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21ChainedFastBackend.php/class/ChainedFastBackend/9" title="Defines a backend with a fast and a consistent backend chain." class="local">\Drupal\Core\Cache\ChainedFastBackend</a> @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testGetDoesNotHitConsistentBackend() {
    $consistent_cache = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    $timestamp_cid = ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo';
    // Use the request time because that is what we will be comparing against.
    $timestamp_item = (object) [
        'cid' => $timestamp_cid,
        'data' => (int) $_SERVER['REQUEST_TIME'] - 60,
    ];
    $consistent_cache->expects($this->once())
        ->method('get')
        ->with($timestamp_cid)
        ->willReturn($timestamp_item);
    $consistent_cache->expects($this->never())
        ->method('getMultiple');
    $fast_cache = new MemoryBackend();
    $fast_cache->set('foo', 'baz');
    $chained_fast_backend = new ChainedFastBackend($consistent_cache, $fast_cache, 'foo');
    $this->assertEquals('baz', $chained_fast_backend->get('foo')->data);
}

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