forked from TruCopilot/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomKeyHashFunction.test.php
More file actions
41 lines (33 loc) · 1.33 KB
/
CustomKeyHashFunction.test.php
File metadata and controls
41 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <contact@geolim4.com>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
use Phpfastcache\CacheManager;
use Phpfastcache\Config\ConfigurationOption;
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
use Phpfastcache\Tests\Helper\TestHelper;
chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
$testHelper = new TestHelper('Custom key hash function');
function myAwesomeHashFunction($string)
{
return 'customHash.' . sha1($string);
}
$cacheInstance = CacheManager::getInstance('Files', new ConfigurationOption(['defaultKeyHashFunction' => 'myAwesomeHashFunction']));
$item = $cacheInstance->getItem(str_shuffle(uniqid('pfc', true)));
$item->set(true)->expiresAfter(300);
$cacheInstance->save($item);
if ($item->getEncodedKey() === 'customHash.' . sha1($item->getKey())) {
$testHelper->assertPass('The custom key hash function returned expected hash string: ' . $item->getEncodedKey());
} else {
$testHelper->assertFail('The custom key hash function returned unexpected hash string: ' . $item->getEncodedKey());
}
$testHelper->terminateTest();