3
3
class FileCacheTest extends \PHPUnit_Framework_TestCase
4
4
{
5
5
6
- public function test ()
6
+ /** @var Cache */
7
+ private $ cache ;
8
+
9
+ public function setUp ()
7
10
{
8
- $ cache = new Cache (__DIR__ . "/test_path/ " );
9
-
10
- // get if not set
11
- $ this ->assertNull ($ cache ->get ("foo " ));
12
- $ this ->assertEquals ("default " , $ cache ->get ("foo " , "default " ));
13
-
14
- // test has = false
15
- $ this ->assertFalse ($ cache ->has ("foo " ));
16
-
17
- // set & get if set
18
- $ cache ->set ("foo " , "bar " );
19
- $ this ->assertEquals ("bar " , $ cache ->get ("foo " ));
11
+ $ this ->cache = new Cache (__DIR__ . "/test_path/ " );
12
+ parent ::setUp ();
13
+ }
14
+
15
+ public function testGetHasEmpty ()
16
+ {
17
+ $ this ->assertNull ($ this ->cache ->get ("foo " ));
18
+ $ this ->assertEquals ("default " , $ this ->cache ->get ("foo " , "default " ));
19
+ $ this ->assertFalse ($ this ->cache ->has ("foo " ));
20
+ }
20
21
21
- // test has = true
22
- $ this ->assertTrue ($ cache ->has ("foo " ));
22
+ public function testGetHasExisting ()
23
+ {
24
+ $ this ->cache ->set ("foo " , "bar " );
25
+ $ this ->assertEquals ("bar " , $ this ->cache ->get ("foo " ));
26
+ $ this ->assertTrue ($ this ->cache ->has ("foo " ));
23
27
24
28
//test if cache has been written
25
- $ cache ->writeCache ()->flush (true );
26
- $ this ->assertEquals ("bar " , $ cache ->get ("foo " ));
29
+ $ this ->cache ->writeCache ()->flush (true );
30
+ $ this ->assertEquals ("bar " , $ this ->cache ->get ("foo " ));
31
+ }
27
32
28
- // test remove
29
- $ cache ->forget ("foo " );
30
- $ this ->assertNull ($ cache ->get ("foo " ));
33
+ public function testRemove ()
34
+ {
35
+ $ this ->cache ->set ("foo " , "bar " );
36
+ $ this ->assertEquals ("bar " , $ this ->cache ->get ("foo " ));
37
+ $ this ->cache ->forget ("foo " );
38
+ $ this ->assertNull ($ this ->cache ->get ("foo " ));
39
+ }
31
40
32
- // test remember
33
- $ this ->assertEquals ("bar2 " , $ cache ->remember ("foo2 " , function () {
41
+ public function testRemember ()
42
+ {
43
+ $ this ->assertEquals ("bar2 " , $ this ->cache ->remember ("foo2 " , function () {
34
44
return "bar2 " ;
35
45
}));
36
- $ this ->assertEquals ("bar2 " , $ cache ->remember ("foo2 " , function () {
46
+ $ this ->assertEquals ("bar2 " , $ this -> cache ->remember ("foo2 " , function () {
37
47
return "this will never be set " ;
38
48
}));
49
+ }
39
50
51
+ public function testTimeout ()
52
+ {
40
53
// test timeout
41
- $ cache ->set ("foo3 " , "bar3 " , 1 );
54
+ $ this -> cache ->set ("foo3 " , "bar3 " , 1 );
42
55
sleep (2 );
43
- $ this ->assertNull ($ cache ->get ("foo3 " ));
56
+ $ this ->assertNull ($ this -> cache ->get ("foo3 " ));
44
57
45
58
// test refresh
46
- $ cache ->set ("foo4 " , "bar4 " , 4 );
59
+ $ this -> cache ->set ("foo4 " , "bar4 " , 4 );
47
60
sleep (2 );
48
- $ this ->assertEquals ("bar4 " , $ cache ->get ("foo4 " ));
61
+ $ this ->assertEquals ("bar4 " , $ this -> cache ->get ("foo4 " ));
49
62
sleep (2 );
50
- $ this ->assertEquals ("bar4 " , $ cache ->get ("foo4 " ));
63
+ $ this ->assertEquals ("bar4 " , $ this -> cache ->get ("foo4 " ));
51
64
sleep (5 );
52
- $ this ->assertNull ($ cache ->get ("foo4 " ));
65
+ $ this ->assertNull ($ this ->cache ->get ("foo4 " ));
66
+ }
53
67
54
- // test flush
55
- $ cache ->flush ();
68
+ public function testSerialization ()
69
+ {
70
+ $ this ->cache ->set ('foo4 ' , ['item1 ' , 'item2 ' ]);
71
+ $ this ->assertEquals (['item1 ' , 'item2 ' ], $ this ->cache ->get ('foo4 ' ));
56
72
}
57
73
58
74
}
0 commit comments