class ChainedFastBackendTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest
@coversDefaultClass \Drupal\Core\Cache\ChainedFastBackend @group Cache
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Cache\ChainedFastBackendTest
Expanded class hierarchy of ChainedFastBackendTest
File
- core/
tests/ Drupal/ Tests/ Core/ Cache/ ChainedFastBackendTest.php, line 18 - Contains \Drupal\Tests\Core\Cache\ChainedFastBackendTest.
Namespace
Drupal\Tests\Core\CacheView source
class ChainedFastBackendTest extends UnitTestCase {
/**
* The consistent cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $consistentCache;
/**
* The fast cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $fastCache;
/**
* The cache bin.
*
* @var string
*/
protected $bin;
/**
* Tests a get() on the fast backend, with no hit on the consistent backend.
*/
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);
}
/**
* Tests a fast cache miss gets data from the consistent cache backend.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChainedFastBackendTest:: |
protected | property | The cache bin. | |
ChainedFastBackendTest:: |
protected | property | The consistent cache backend. | |
ChainedFastBackendTest:: |
protected | property | The fast cache backend. | |
ChainedFastBackendTest:: |
public | function | Tests a fast cache miss gets data from the consistent cache backend. | |
ChainedFastBackendTest:: |
public | function | Tests a get() on the fast backend, with no hit on the consistent backend. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 |