function ChainedFastBackendTest::testSetInvalidDataFastBackend

Tests a get() on consistent backend without saving on fast backend.

File

core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php, line 68

Class

ChainedFastBackendTest
@coversDefaultClass \Drupal\Core\Cache\ChainedFastBackend @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testSetInvalidDataFastBackend() : void {
    $cid = $this->randomString();
    $item = (object) [
        'cid' => $cid,
        'data' => serialize($this->randomObject()),
        'created' => ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo',
        'expire' => Cache::PERMANENT,
        'tags' => [],
        'valid' => FALSE,
    ];
    $consistent_cache = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    $consistent_cache->expects($this->once())
        ->method('get')
        ->withAnyParameters()
        ->willReturn(FALSE);
    $consistent_cache->expects($this->once())
        ->method('getMultiple')
        ->withAnyParameters()
        ->willReturn([
        $item,
    ]);
    $fast_cache = new MemoryBackend(new Time());
    $chained_fast_backend = new ChainedFastBackend($consistent_cache, $fast_cache, 'foo');
    // Perform a get using the allowing invalid data parameter.
    $this->assertEquals($item, $chained_fast_backend->get($cid, TRUE));
    // Perform a get directly on the fast cache to guarantee the invalid data
    // were not saved there.
    $this->assertEquals(NULL, $fast_cache->get($cid), 'Invalid data was not saved on the fast cache.');
}

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