forked from TruCopilot/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRedisCustomClient.test.php
More file actions
44 lines (38 loc) · 1.44 KB
/
RedisCustomClient.test.php
File metadata and controls
44 lines (38 loc) · 1.44 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
42
43
44
<?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\Exceptions\PhpfastcacheDriverCheckException;
use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException;
use Phpfastcache\Tests\Helper\TestHelper;
use Phpfastcache\Drivers\Redis\Config as RedisConfig;
use Redis as RedisClient;
chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
$testHelper = new TestHelper('Redis custom client');
try {
if (!class_exists(RedisClient::class)) {
throw new PhpfastcacheDriverCheckException('Unable to test Redis client because the extension seems to be missing');
}
try{
$redisClient = new RedisClient();
$redisClient->connect('127.0.0.1', 6379, 5);
}catch (\RedisException $e){
throw new PhpfastcacheDriverConnectException('Redis server unreachable.');
}
$redisClient->select(0);
$cacheInstance = CacheManager::getInstance('Redis', (new RedisConfig())->setRedisClient($redisClient));
$testHelper->runCRUDTests($cacheInstance);
} catch (\RedisException $e) {
$testHelper->assertFail('A Redis exception occurred: ' . $e->getMessage());
}
$testHelper->terminateTest();