colly_wyx
2018-05-18 50a53f7db63c5729b0ddbc93367117cf35ccf03c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 * PhpUnderControl_PhalApiCacheFile_Test
 *
 * 针对 ../../PhalApi/Cache/File.php PhalApi_Cache_File 类的PHPUnit单元测试
 *
 * @author: dogstar 20150226
 */
 
require_once dirname(__FILE__) . '/../test_env.php';
 
if (!class_exists('PhalApi_Cache_File')) {
    require dirname(__FILE__) . '/../../PhalApi/Cache/File.php';
}
 
class PhpUnderControl_PhalApiCacheFile_Test extends PHPUnit_Framework_TestCase
{
    public $phalApiCacheFile;
 
    protected function setUp()
    {
        parent::setUp();
 
        @unlink(dirname(__FILE__) . '/cache');
 
        $config['path'] = dirname(__FILE__);
        $this->phalApiCacheFile = new PhalApi_Cache_File($config);
    }
 
    protected function tearDown()
    {
    }
 
 
    /**
     * @group testSet
     */ 
    public function testSet()
    {
        $key = 'aYearKey';
        $value = 2015;
        $expire = '200';
 
        $rs = $this->phalApiCacheFile->set($key, $value, $expire);
    }
 
    /**
     * @group testGet
     * @depends testSet
     */ 
    public function testGet()
    {
        $key = 'aYearKey';
 
        $rs = $this->phalApiCacheFile->get($key);
 
        $this->assertSame(2015, $rs);
    }
 
    /**
     * @group testDelete
     * @depends testSet
     */ 
    public function testDelete()
    {
        $key = 'aYearKey';
 
        $this->phalApiCacheFile->delete($key);
 
        $rs = $this->phalApiCacheFile->get($key);
 
        $this->assertSame(NULL, $rs);
    }
 
    public function testGetAfterSet()
    {
        $key = 'anotherKey';
 
        $value = array('name' => 'dogstar');
 
        $this->phalApiCacheFile->set($key, $value);
 
        $this->assertSame($value, $this->phalApiCacheFile->get($key));
    }
 
    public function testExpire() 
    {
        $key = 'tmpKey';
        $value = 'somethinghere~';
        $expire = 2;
 
        $this->phalApiCacheFile->set($key, $value, $expire);
 
        $this->assertSame($value, $this->phalApiCacheFile->get($key));
 
        sleep(3);
 
        $this->assertSame(NULL, $this->phalApiCacheFile->get($key));
    }
 
}