ChainedFastBackendTest.php in Zircon Profile 8.0
File
core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php
View source
<?php
namespace Drupal\Tests\Core\Cache;
use Drupal\Core\Cache\ChainedFastBackend;
use Drupal\Core\Cache\MemoryBackend;
use Drupal\Tests\UnitTestCase;
class ChainedFastBackendTest extends UnitTestCase {
protected $consistentCache;
protected $fastCache;
protected $bin;
public function testGetDoesntHitConsistentBackend() {
$consistent_cache = $this
->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$timestamp_cid = ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo';
$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);
}
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');
$consistent_cache
->expects($this
->once())
->method('get')
->with($timestamp_item->cid)
->will($this
->returnValue($timestamp_item));
$consistent_cache
->expects($this
->once())
->method('getMultiple')
->with(array(
$cache_item->cid,
))
->will($this
->returnValue(array(
$cache_item->cid => $cache_item,
)));
$fast_cache
->expects($this
->once())
->method('getMultiple')
->with(array(
$cache_item->cid,
))
->will($this
->returnValue(array(
$cache_item->cid => $cache_item,
)));
$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);
}
}