You are here

public function ChainedFastBackendTest::testGetDoesntHitConsistentBackend in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testGetDoesntHitConsistentBackend()

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

File

core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php, line 44
Contains \Drupal\Tests\Core\Cache\ChainedFastBackendTest.

Class

ChainedFastBackendTest
@coversDefaultClass \Drupal\Core\Cache\ChainedFastBackend @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testGetDoesntHitConsistentBackend() {
  $consistent_cache = $this
    ->getMock('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) array(
    '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('foo');
  $fast_cache
    ->set('foo', 'baz');
  $chained_fast_backend = new ChainedFastBackend($consistent_cache, $fast_cache, 'foo');
  $this
    ->assertEquals('baz', $chained_fast_backend
    ->get('foo')->data);
}