function CacheCollectorTest::testUpdateCacheMerge
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheMerge()
- 8.9.x core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheMerge()
- 11.x core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheMerge()
Tests a cache hit, then item updated by a different request.
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ CacheCollectorTest.php, line 266
Class
- CacheCollectorTest
- @coversDefaultClass \Drupal\Core\Cache\CacheCollector @group Cache
Namespace
Drupal\Tests\Core\CacheCode
public function testUpdateCacheMerge() : void {
$key = $this->randomMachineName();
$value = $this->randomMachineName();
$this->collector
->setCacheMissData($key, $value);
$this->collector
->get($key);
// Set up mock objects for the expected calls, first a lock acquire, then
// cache get to look for existing cache entries, which does find
// and then it merges them.
$this->lock
->expects($this->once())
->method('acquire')
->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector')
->willReturn(TRUE);
$cache = (object) [
'data' => [
'other key' => 'other value',
],
'created' => (int) $_SERVER['REQUEST_TIME'] + 1,
];
$this->collector
->setCacheCreated($cache->created);
$this->cacheBackend
->expects($this->once())
->method('get')
->with($this->cid)
->willReturn($cache);
$this->cacheBackend
->expects($this->once())
->method('set')
->with($this->cid, [
'other key' => 'other value',
$key => $value,
], Cache::PERMANENT, []);
$this->lock
->expects($this->once())
->method('release')
->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector');
// Destruct the object to trigger the update data process.
$this->collector
->destruct();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.