function ChainedFastBackendTest::testGetDoesNotHitConsistentBackend

Same name in other branches
  1. 9 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 \Drupal\Core\Cache\ChainedFastBackend @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)
        ->will($this->returnValue($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.