function CacheCollectorTest::testUpdateCacheDelete
Tests updating the cache after a delete.
File
- 
              core/tests/ Drupal/ Tests/ Core/ Cache/ CacheCollectorTest.php, line 333 
Class
- CacheCollectorTest
- @coversDefaultClass \Drupal\Core\Cache\CacheCollector[[api-linebreak]] @group Cache
Namespace
Drupal\Tests\Core\CacheCode
public function testUpdateCacheDelete() : void {
  $key = $this->randomMachineName();
  $value = $this->randomMachineName();
  $cache = (object) [
    'data' => [
      $key => $value,
    ],
    'created' => (int) $_SERVER['REQUEST_TIME'],
  ];
  // Set up mock expectation, on the second call the with the second argument
  // set to TRUE because we triggered a cache invalidation.
  $allow_invalid = [
    FALSE,
    TRUE,
  ];
  $this->cacheBackend
    ->expects($this->exactly(2))
    ->method('get')
    ->with($this->cid, $this->callback(function ($value) use (&$allow_invalid) {
    return array_shift($allow_invalid) === $value;
  }))
    ->willReturn($cache);
  $this->collector
    ->delete($key);
  // Set up mock objects for the expected calls, first a lock acquire, then
  // a cache set and finally the lock is released again.
  $this->lock
    ->expects($this->once())
    ->method('acquire')
    ->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector')
    ->willReturn(TRUE);
  $this->cacheBackend
    ->expects($this->once())
    ->method('set')
    ->with($this->cid, [], 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.
