public function ChainedFastBackendTest::testFallThroughToConsistentCache in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testFallThroughToConsistentCache()
Tests a fast cache miss gets data from the consistent cache backend.
File
- core/
tests/ Drupal/ Tests/ Core/ Cache/ ChainedFastBackendTest.php, line 69 - Contains \Drupal\Tests\Core\Cache\ChainedFastBackendTest.
Class
- ChainedFastBackendTest
- @coversDefaultClass \Drupal\Core\Cache\ChainedFastBackend @group Cache
Namespace
Drupal\Tests\Core\CacheCode
public function testFallThroughToConsistentCache() {
$timestamp_item = (object) array(
'cid' => ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo',
'data' => time() + 60,
);
$cache_item = (object) array(
'cid' => 'foo',
'data' => 'baz',
'created' => time(),
'expire' => time() + 3600,
'tags' => [
'tag',
],
);
$consistent_cache = $this
->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$fast_cache = $this
->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
// We should get a call for the timestamp on the consistent backend.
$consistent_cache
->expects($this
->once())
->method('get')
->with($timestamp_item->cid)
->will($this
->returnValue($timestamp_item));
// We should get a call for the cache item on the consistent backend.
$consistent_cache
->expects($this
->once())
->method('getMultiple')
->with(array(
$cache_item->cid,
))
->will($this
->returnValue(array(
$cache_item->cid => $cache_item,
)));
// We should get a call for the cache item on the fast backend.
$fast_cache
->expects($this
->once())
->method('getMultiple')
->with(array(
$cache_item->cid,
))
->will($this
->returnValue(array(
$cache_item->cid => $cache_item,
)));
// We should get a call to set the cache item on the fast backend.
$fast_cache
->expects($this
->once())
->method('set')
->with($cache_item->cid, $cache_item->data, $cache_item->expire);
$chained_fast_backend = new ChainedFastBackend($consistent_cache, $fast_cache, 'foo');
$this
->assertEquals('baz', $chained_fast_backend
->get('foo')->data);
}