8
8
9
9
class FilePathCacheTest extends TestCase
10
10
{
11
- public function testConstruct ()
11
+ public function testConstruct (): void
12
12
{
13
13
$ cache = new FilePathCache ('/imagination ' , 'bacon.porn ' );
14
14
$ this ->assertTrue ($ cache instanceof CacheInterface);
15
15
16
- $ this ->assertAttributeEquals (
16
+ $ refClass = new \ReflectionClass (FilePathCache::class);
17
+ $ dirProp = $ refClass ->getProperty ('dir ' );
18
+ $ dirProp ->setAccessible (true );
19
+
20
+ $ filenameProp = $ refClass ->getProperty ('filename ' );
21
+ $ filenameProp ->setAccessible (true );
22
+
23
+ $ this ->assertSame (
17
24
'/imagination ' ,
18
- 'dir ' ,
19
- $ cache
25
+ $ dirProp ->getValue ($ cache )
20
26
);
21
27
22
- $ this ->assertAttributeEquals (
28
+ $ this ->assertSame (
23
29
'bacon.porn ' ,
24
- 'filename ' ,
25
- $ cache
30
+ $ filenameProp ->getValue ($ cache )
26
31
);
27
32
}
28
33
29
- public function testHas ()
34
+ public function testHas (): void
30
35
{
31
36
// Check fail
32
37
$ cache = new FilePathCache ('/imagination ' , 'bacon.porn ' );
@@ -37,31 +42,26 @@ public function testHas()
37
42
$ this ->assertTrue ($ cache ->has ('bacon ' ));
38
43
}
39
44
40
- /**
41
- * @expectedException \RunTimeException
42
- *
43
- */
44
- public function testGetException ()
45
+ public function testGetException (): void
45
46
{
47
+ $ this ->expectException (\RuntimeException::class);
46
48
$ cache = new FilePathCache ('/imagination ' , 'bacon.porn ' );
47
49
$ cache ->get ('bacon ' );
48
50
}
49
51
50
- public function testGet ()
52
+ public function testGet (): void
51
53
{
52
54
$ cache = new FilePathCache ('' , __FILE__ );
53
55
$ this ->assertEquals (file_get_contents (__FILE__ ), $ cache ->get ('bacon ' ));
54
56
}
55
57
56
- /**
57
- * @expectedException \RuntimeException
58
- */
59
- public function testSetMayNotWriteFile ()
58
+ public function testSetMayNotWriteFile (): void
60
59
{
60
+ $ this ->expectException (\RuntimeException::class);
61
61
restore_error_handler (); // Previous test fails, so doesn't unset.
62
62
$ time = time ();
63
63
$ sentence = 'I am, what I am. Cached data, please don \'t hate, '
64
- . 'for we are all equals. Except you, you \'re a dick. ' ;
64
+ . 'for we are all equals. Except you, you \'re a dick. ' ;
65
65
$ base = '/tmp/_cachetest. ' . $ time . '/ ' ;
66
66
mkdir ($ base , 0777 );
67
67
mkdir ($ base .'readonly ' , 0400 , true );
@@ -70,33 +70,28 @@ public function testSetMayNotWriteFile()
70
70
$ cache ->set ('bacon ' , $ sentence );
71
71
}
72
72
73
- /**
74
- * @expectedException \RuntimeException
75
- */
76
- public function testSetMayNotWriteDir ()
73
+ public function testSetMayNotWriteDir (): void
77
74
{
75
+ $ this ->expectException (\RuntimeException::class);
78
76
restore_error_handler (); // Previous test fails, so doesn't unset.
79
77
$ time = time ()+1 ;
80
78
$ sentence = 'I am, what I am. Cached data, please don \'t hate, '
81
- . 'for we are all equals. Except you, you \'re a dick. ' ;
79
+ . 'for we are all equals. Except you, you \'re a dick. ' ;
82
80
$ base = '/tmp/_cachetest. ' . $ time . '/ ' ;
83
81
mkdir ($ base , 0400 , true );
84
82
85
83
$ cache = new FilePathCache ($ base .'readonly ' , 'bacon. ' .$ time .'.hammertime ' );
86
84
87
85
$ cache ->set ('bacon ' , $ sentence );
88
-
89
86
}
90
87
91
- /**
92
- * @expectedException \RuntimeException
93
- */
94
- public function testSetCanNotWriteToFileThatExists ()
88
+ public function testSetCanNotWriteToFileThatExists (): void
95
89
{
90
+ $ this ->expectException (\RuntimeException::class);
96
91
restore_error_handler (); // Previous test fails, so doesn't unset.
97
92
$ time = time ()+333 ;
98
93
$ sentence = 'I am, what I am. Cached data, please don \'t hate, '
99
- . 'for we are all equals. Except you, you \'re a dick. ' ;
94
+ . 'for we are all equals. Except you, you \'re a dick. ' ;
100
95
$ base = '/tmp/_cachetest. ' . $ time . '/ ' ;
101
96
mkdir ($ base , 0777 );
102
97
@@ -110,7 +105,7 @@ public function testSetCanNotWriteToFileThatExists()
110
105
$ cache ->set ('bacon ' , $ sentence );
111
106
}
112
107
113
- public function testSetSuccess ()
108
+ public function testSetSuccess (): void
114
109
{
115
110
$ time = time ();
116
111
$ sentence = 'I am, what I am. Cached data, please don \'t hate, '
@@ -122,17 +117,15 @@ public function testSetSuccess()
122
117
$ this ->assertEquals ($ sentence , file_get_contents ($ base .'bacon. ' .$ time ));
123
118
}
124
119
125
- /**
126
- * @expectedException \RuntimeException
127
- */
128
- public function testRemoveFails ()
120
+ public function testRemoveFails (): void
129
121
{
122
+ $ this ->expectException (\RuntimeException::class);
130
123
$ cache = new FilePathCache ('/dev ' , 'null ' );
131
124
132
125
$ cache ->remove ('bacon ' );
133
126
}
134
127
135
- public function testRemoveSuccess ()
128
+ public function testRemoveSuccess (): void
136
129
{
137
130
$ time = time ();
138
131
$ sentence = 'I am, what I am. Cached data, please don \'t hate, '
@@ -145,7 +138,7 @@ public function testRemoveSuccess()
145
138
$ this ->assertTrue ($ cache ->remove ('bacon ' ));
146
139
}
147
140
148
- public function testCachedFile ()
141
+ public function testCachedFile (): void
149
142
{
150
143
$ method = new \ReflectionMethod (FilePathCache::class, 'cachedFile ' );
151
144
0 commit comments