function CacheTestBase::checkCacheExists

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Cache/CacheTestBase.php \Drupal\Tests\system\Functional\Cache\CacheTestBase::checkCacheExists()
  2. 8.9.x core/modules/system/src/Tests/Cache/CacheTestBase.php \Drupal\system\Tests\Cache\CacheTestBase::checkCacheExists()
  3. 8.9.x core/modules/system/tests/src/Functional/Cache/CacheTestBase.php \Drupal\Tests\system\Functional\Cache\CacheTestBase::checkCacheExists()
  4. 10 core/modules/system/tests/src/Functional/Cache/CacheTestBase.php \Drupal\Tests\system\Functional\Cache\CacheTestBase::checkCacheExists()

Checks whether or not a cache entry exists.

Parameters

string $cid: The cache id.

mixed $var: The variable the cache should contain.

string|null $bin: The bin the cache item was stored in.

Return value

bool TRUE on pass, FALSE on fail.

2 calls to CacheTestBase::checkCacheExists()
CacheTestBase::assertCacheExists in core/modules/system/tests/src/Functional/Cache/CacheTestBase.php
Asserts that a cache entry exists.
ClearTest::testFlushAllCaches in core/modules/system/tests/src/Functional/Cache/ClearTest.php
Tests drupal_flush_all_caches().

File

core/modules/system/tests/src/Functional/Cache/CacheTestBase.php, line 31

Class

CacheTestBase
Provides helper methods for cache tests.

Namespace

Drupal\Tests\system\Functional\Cache

Code

protected function checkCacheExists($cid, $var, $bin = NULL) : bool {
    if ($bin == NULL) {
        $bin = $this->defaultBin;
    }
    $cached = \Drupal::cache($bin)->get($cid);
    return isset($cached->data) && $cached->data == $var;
}

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