public function GenericCacheBackendUnitTestBase::testValueTypeIsKept in Drupal 8
Same name in this branch
- 8 core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase::testValueTypeIsKept()
- 8 core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php \Drupal\system\Tests\Cache\GenericCacheBackendUnitTestBase::testValueTypeIsKept()
Tests data type preservation.
File
- core/
modules/ system/ src/ Tests/ Cache/ GenericCacheBackendUnitTestBase.php, line 262
Class
- GenericCacheBackendUnitTestBase
- Tests any cache backend.
Namespace
Drupal\system\Tests\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
->assert(is_object($object), sprintf("Backend returned an object for cache id %s.", $cid));
$this
->assertIdentical($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid));
}
}