function CacheCollectorTest::testUpdateCache

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

Tests updating the cache after a set.

File

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

Class

CacheCollectorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21CacheCollector.php/class/CacheCollector/9" title="Default implementation for CacheCollectorInterface." class="local">\Drupal\Core\Cache\CacheCollector</a> @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testUpdateCache() {
    $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 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')
        ->willReturn(TRUE);
    $this->cacheBackend
        ->expects($this->once())
        ->method('get')
        ->with($this->cid, FALSE);
    $this->cacheBackend
        ->expects($this->once())
        ->method('set')
        ->with($this->cid, [
        $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.