function CacheCollectorTest::testUpdateCacheInvalidatedConflict

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

Tests updating the cache when there is a conflict after cache invalidation.

File

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

Class

CacheCollectorTest
@coversDefaultClass \Drupal\Core\Cache\CacheCollector @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testUpdateCacheInvalidatedConflict() {
    $key = $this->randomMachineName();
    $value = $this->randomMachineName();
    // Set up mock cache get with conflicting entries.
    $this->cacheBackend
        ->expects($this->exactly(2))
        ->method('get')
        ->with($this->cid)
        ->willReturnOnConsecutiveCalls((object) [
        'data' => [
            $key => $value,
        ],
        'created' => (int) $_SERVER['REQUEST_TIME'],
    ], (object) [
        'data' => [
            $key => $value,
        ],
        'created' => (int) $_SERVER['REQUEST_TIME'] + 1,
    ]);
    $this->cacheBackend
        ->expects($this->once())
        ->method('invalidate')
        ->with($this->cid);
    $this->collector
        ->set($key, 'new value');
    // Set up mock objects for the expected calls, first a lock acquire, then
    // when cache get finds conflicting entries it deletes the cache and aborts.
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector')
        ->willReturn(TRUE);
    $this->cacheBackend
        ->expects($this->once())
        ->method('delete')
        ->with($this->cid);
    $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.