function CacheCollectorTest::testGetFromCache

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

Tests returning value from the collected cache.

File

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

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 testGetFromCache() {
    $key = $this->randomMachineName();
    $value = $this->randomMachineName();
    $cache = (object) [
        'data' => [
            $key => $value,
        ],
        'created' => (int) $_SERVER['REQUEST_TIME'],
    ];
    $this->cacheBackend
        ->expects($this->once())
        ->method('get')
        ->with($this->cid)
        ->willReturn($cache);
    $this->assertTrue($this->collector
        ->has($key));
    $this->assertEquals($value, $this->collector
        ->get($key));
    $this->assertEquals(0, $this->collector
        ->getCacheMisses());
}

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