forked from jysperm/LightPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCacheTest.php
103 lines (89 loc) · 2.38 KB
/
CacheTest.php
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
102
103
<?php
namespace LightPHP\Test;
use LightPHP\Cache\Adapter\FileCache;
use LightPHP\Cache\Adapter\MemCache;
use LightPHP\Cache\Adapter\SimpleCache;
use LightPHP\Cache\CacheAgent;
class CacheTest extends \PHPUnit_Framework_TestCase
{
/**
* @param CacheAgent $agent
*
* @dataProvider provider
*/
public function testSet($agent)
{
$agent->set("key", "value");
}
/**
* @param CacheAgent $agent
*
* @dataProvider provider
* @depends testSet
*/
public function testGetData($agent)
{
$this->assertEquals("value", $agent->fetch("key"));
$this->assertEquals("value", $agent["key"]);
$this->assertEquals("value", $agent->get("key"));
$this->assertEquals("default value", $agent->get("key_not_exist", "default value"));
}
/**
* @param CacheAgent $agent
*
* @dataProvider provider
* @depends testSet
* @expectedException LightPHP\Cache\Exception\NoDataException
*/
public function testFetchException($agent)
{
$agent->fetch("key_not_exist");
}
/**
* @param CacheAgent $agent
*
* @dataProvider provider
* @depends testSet
*/
public function testExist($agent)
{
$this->assertEquals(true, $agent->exist("key"));
$this->assertEquals(false, $agent->exist("key_not_exist"));
$this->assertEquals(false, isset($agent["key_not_exist"]));
}
/**
* @param CacheAgent $agent
*
* @dataProvider provider
*/
public function testCheck($agent)
{
$closure = function () {
throw new \Exception;
};
$this->assertEquals("value", $agent->check("key", $closure));
$this->assertEquals("new value", $agent->check("new_key", function () {
return "new value";
}));
}
/**
* @param CacheAgent $agent
*
* @dataProvider provider
* @depends testCheck
*/
public function testDelete($agent)
{
$agent->delete("new_key");
$this->assertEquals(false, $agent->exist("new_key"));
$this->assertEquals(true, $agent->exist("key"));
}
public function provider()
{
return [
[new CacheAgent(new MemCache(null, "prefix"))],
[new CacheAgent(new FileCache)],
[new CacheAgent(new SimpleCache)]
];
}
}