function CacheCollectorTest::testUpdateCacheClear

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

Tests a clear of the cache collector.

File

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

Class

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

Namespace

Drupal\Tests\Core\Cache

Code

public function testUpdateCacheClear() : void {
    $key = $this->randomMachineName();
    $value = $this->randomMachineName();
    // Set the data and request it.
    $this->collector
        ->setCacheMissData($key, $value);
    $this->assertEquals($value, $this->collector
        ->get($key));
    $this->assertEquals($value, $this->collector
        ->get($key));
    // Should have been added to the storage and only be requested once.
    $this->assertEquals(1, $this->collector
        ->getCacheMisses());
    // Clear the collected cache, should call it again.
    $this->cacheBackend
        ->expects($this->once())
        ->method('delete')
        ->with($this->cid);
    $this->cacheTagsInvalidator
        ->expects($this->never())
        ->method('invalidateTags');
    $this->collector
        ->clear();
    $this->assertEquals($value, $this->collector
        ->get($key));
    $this->assertEquals(2, $this->collector
        ->getCacheMisses());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.