Completed
Pull Request — 5.1 (#1327)
by
unknown
05:23
created

redisTest::testExpire()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
12
/**
13
 * Redis缓存驱动测试
14
 * @author    7IN0SAN9 <[email protected]>
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 4
Loading history...
15
 */
16
17
namespace tests\thinkphp\library\think\cache\driver;
18
19
class redisTest extends cacheTestCase
1 ignored issue
show
Coding Style introduced by
Missing class doc comment
Loading history...
Coding Style introduced by
Class name must begin with a capital letter
Loading history...
20
{
21
    private $_cacheInstance = null;
22
23
    protected function setUp()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
24
    {
25
        if (!extension_loaded("redis")) {
26
            $this->markTestSkipped("Redis没有安装,已跳过测试!");
27
        }
28
        \think\Cache::connect(array('type' => 'redis', 'expire' => 2));
0 ignored issues
show
Bug introduced by
The type think\Cache was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
    }
30
31
    protected function getCacheInstance()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
32
    {
33
        if (null === $this->_cacheInstance) {
34
            $this->_cacheInstance = new \think\cache\driver\Redis(['length' => 3]);
0 ignored issues
show
Bug introduced by
The type think\cache\driver\Redis was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
        }
36
        return $this->_cacheInstance;
37
    }
38
39
    public function testGet()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
40
    {
41
        $cache = $this->prepare();
42
        $this->assertEquals('string_test', $cache->get('string_test'));
43
        $this->assertEquals(11, $cache->get('number_test'));
44
        $result = $cache->get('array_test');
45
        $this->assertEquals('array_test', $result['array_test']);
46
    }
47
48
    public function testStoreSpecialValues()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
49
    {
50
        $redis = new \think\cache\driver\Redis(['length' => 3]);
51
        $redis->set('key', 'value');
52
        $redis->get('key');
53
54
        $redis->handler()->setnx('key', 'value');
55
        $value = $redis->handler()->get('key');
56
        $this->assertEquals('value', $value);
57
58
        $redis->handler()->hset('hash', 'key', 'value');
59
        $value = $redis->handler()->hget('hash', 'key');
60
        $this->assertEquals('value', $value);
61
    }
62
63
    public function testExpire()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
64
    {
65
    }
66
}
67