function GenericCacheBackendUnitTestBase::testValueTypeIsKept
Same name in this branch
- 8.9.x core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php \Drupal\system\Tests\Cache\GenericCacheBackendUnitTestBase::testValueTypeIsKept()
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testValueTypeIsKept()
- 10 core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testValueTypeIsKept()
- 11.x core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testValueTypeIsKept()
Tests data type preservation.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Cache/ GenericCacheBackendUnitTestBase.php, line 257
Class
- GenericCacheBackendUnitTestBase
- Tests any cache backend.
Namespace
Drupal\KernelTests\Core\CacheCode
public function testValueTypeIsKept() {
$backend = $this->getCacheBackend();
$variables = [
'test1' => 1,
'test2' => '0',
'test3' => '',
'test4' => 12.64,
'test5' => FALSE,
'test6' => [
1,
2,
3,
],
];
// Create cache entries.
foreach ($variables as $cid => $data) {
$backend->set($cid, $data);
}
// Retrieve and test cache objects.
foreach ($variables as $cid => $value) {
$object = $backend->get($cid);
$this->assertIsObject($object, sprintf("Backend returned an object for cache id %s.", $cid));
$this->assertSame($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.