function LruMemoryCacheTest::assertCacheData
Asserts that the given cache data matches the data in the memory cache.
Parameters
\Drupal\Core\Cache\MemoryCache\LruMemoryCache $lru_cache: The LRU cache under test.
array $cache_data: Array whose first element is the cache ID and whose second element is the value to check. This should contain all the keys in the cache and in the expected order.
5 calls to LruMemoryCacheTest::assertCacheData()
- LruMemoryCacheTest::testGetSetDelete in core/
tests/ Drupal/ Tests/ Core/ Cache/ LruMemoryCacheTest.php - Tests getting, setting and deleting items from the LRU memory cache.
- LruMemoryCacheTest::testInvalidate in core/
tests/ Drupal/ Tests/ Core/ Cache/ LruMemoryCacheTest.php - Tests invalidation from the LRU memory cache.
- LruMemoryCacheTest::testInvalidateNumeric in core/
tests/ Drupal/ Tests/ Core/ Cache/ LruMemoryCacheTest.php - Tests invalidation with numeric keys from the LRU memory cache.
- LruMemoryCacheTest::testSetMultiple in core/
tests/ Drupal/ Tests/ Core/ Cache/ LruMemoryCacheTest.php - Tests setting multiple items in the LRU memory cache.
- LruMemoryCacheTest::testSetNumericKeys in core/
tests/ Drupal/ Tests/ Core/ Cache/ LruMemoryCacheTest.php - Tests setting items with numeric keys in the LRU memory cache.
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ LruMemoryCacheTest.php, line 355
Class
- LruMemoryCacheTest
- @coversDefaultClass \Drupal\Core\Cache\MemoryCache\LruMemoryCache @group Cache
Namespace
Drupal\Tests\Core\CacheCode
protected function assertCacheData(LruMemoryCache $lru_cache, array $cache_data) : void {
// Use reflection to access data because using ::get() affects the LRU
// cache.
$reflectedClass = new \ReflectionClass($lru_cache);
$reflection = $reflectedClass->getProperty('cache');
$cache = $reflection->getValue($lru_cache);
$keys = [];
foreach ($cache_data as $item) {
$keys[] = $item[0];
$this->assertSame($item[1], $cache[$item[0]]->data, "{$item[0]} found in cache.");
}
// Ensure the cache only contains the supply keys and the order is as
// expected.
$this->assertSame($keys, array_keys($cache));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.