function CacheCollectorTest::testUpdateCacheDelete

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheDelete()
  2. 10 core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheDelete()
  3. 11.x core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheDelete()

Tests updating the cache after a delete.

File

core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php, line 301

Class

CacheCollectorTest
@coversDefaultClass \Drupal\Core\Cache\CacheCollector[[api-linebreak]] @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testUpdateCacheDelete() {
  $key = $this->randomMachineName();
  $value = $this->randomMachineName();
  $cache = (object) [
    'data' => [
      $key => $value,
    ],
    'created' => (int) $_SERVER['REQUEST_TIME'],
  ];
  $this->cacheBackend
    ->expects($this->at(0))
    ->method('get')
    ->with($this->cid)
    ->will($this->returnValue($cache));
  $this->collector
    ->delete($key);
  // Set up mock objects for the expected calls, first a lock acquire, then
  // cache get to look for conflicting cache entries, 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')
    ->will($this->returnValue(TRUE));
  // The second argument is set to TRUE because we triggered a cache
  // invalidation.
  $this->cacheBackend
    ->expects($this->at(0))
    ->method('get')
    ->with($this->cid, TRUE)
    ->will($this->returnValue($cache));
  $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.