@@ -29,10 +29,12 @@ public static function setUpBeforeClass(): void
29
29
public function setUp (): void
30
30
{
31
31
$ this ->clearFiles ();
32
- Configure::write (FileCache::ConfigurePath,
32
+ Configure::write (
33
+ FileCache::ConfigurePath,
33
34
array (
34
35
'BaseDir ' => self ::getPath ()
35
- ));
36
+ )
37
+ );
36
38
}
37
39
38
40
public function tearDown (): void
@@ -59,25 +61,20 @@ protected function clearFiles()
59
61
}
60
62
61
63
/**
62
- * @expectedException \Faid\Configure\ConfigureException
63
64
*/
64
65
public function testWithEmptyConfig ()
65
66
{
67
+ $ this ->expectException (ConfigureException::class);
66
68
Configure::write (FileCache::ConfigurePath, null );
67
69
new FileCache ();
68
70
}
69
71
70
- public function testAutoload ()
71
- {
72
- new FileCache ();
73
- }
74
-
75
72
/**
76
73
* Создает кеш с пустым ключом
77
- * @expectedException Exception
78
74
*/
79
75
public function testSetWithEmptyKey ()
80
76
{
77
+ $ this ->expectException (Exception::class);
81
78
$ instance = new FileCache ();
82
79
$ instance ->set ('' , array (1 , 2 , 3 ), self ::CacheActualTime);
83
80
}
@@ -91,18 +88,15 @@ public function testSet()
91
88
$ instance = new FileCache ();
92
89
$ instance ->set (self ::KeyFixture, $ fixture , self ::CacheActualTime);
93
90
$ testPath = self ::getPath () . (self ::KeyFixture);
94
- if (!file_exists ($ testPath )) {
95
- die ($ testPath );
96
- $ this ->fail ();
97
- }
91
+ $ this ->assertTrue (file_exists ($ testPath ), "File $ testPath does not exist " );
98
92
}
99
93
100
- /**
94
+ /**t
101
95
* Проверяет загрузку несуществующего кеша
102
- * @expectedException Exception
103
96
*/
104
97
public function testGetWithUknownKey ()
105
98
{
99
+ $ this ->expectException (Exception::class);
106
100
$ instance = new FileCache ();
107
101
$ instance ->get (self ::UnknownKeyFixture);
108
102
}
@@ -112,6 +106,7 @@ public function testGetWithUknownKey()
112
106
*/
113
107
public function testGetSecurity ()
114
108
{
109
+ $ this ->expectException (Exception::class);
115
110
$ instance = new FileCache ();
116
111
$ instance ->get ('../FileCacheTest.php ' );
117
112
}
@@ -131,16 +126,15 @@ public function testGet()
131
126
// cover cached variant
132
127
$ data = $ instance ->get (self ::KeyFixture);
133
128
$ this ->assertEquals ($ data , $ initialData );
134
-
135
129
}
136
130
137
131
138
132
/**
139
133
* Проверяем очистку кеша при несуществующем хеше
140
- * @expectedException Exception
141
134
*/
142
135
public function testClearWithUnknownKey ()
143
136
{
137
+ $ this ->ExpectException (Exception::class);
144
138
$ instance = new FileCache ();
145
139
$ instance ->clear (self ::UnknownKeyFixture);
146
140
}
@@ -150,6 +144,7 @@ public function testClearWithUnknownKey()
150
144
*/
151
145
public function testClear ()
152
146
{
147
+ $ this ->expectException (Faid \Cache \Exception::class);
153
148
$ key = 'test ' ;
154
149
$ instance = new FileCache ();
155
150
$ data = array (1 , 2 , 3 , 4 );
@@ -158,12 +153,9 @@ public function testClear()
158
153
159
154
$ instance ->clear ($ key );
160
155
161
- try {
162
- $ instance ->get ($ key );
163
- $ this ->fail ('Exception must be thrown ' );
164
- } catch (Exception $ e ) {
165
-
166
- }
156
+ $ this ->expectException (Exception::class);
157
+ $ instance ->get ($ key );
158
+ $ this ->fail ('Exception must be thrown ' );
167
159
}
168
160
169
161
public function testUnknownCacheIsActual ()
@@ -192,15 +184,16 @@ public function testIsActual()
192
184
}
193
185
194
186
/**
195
- * @expectedException Exception
187
+ *
196
188
*/
197
189
public function testGetNotActualCache ()
198
190
{
191
+ $ this ->expectException (Exception::class);
199
192
$ key = 'test ' ;
200
193
$ time = 1 ;
201
194
$ instance = new FileCache ();
202
195
$ instance ->set ($ key , 'test ' , $ time );
203
- sleep ($ time );
196
+ sleep ($ time + 1 );
204
197
$ instance ->get ($ key );
205
198
}
206
199
@@ -215,6 +208,5 @@ public function testGetPersistentCache()
215
208
$ this ->assertEquals ($ value , $ instance ->get ($ key ));
216
209
sleep (1 );
217
210
$ this ->assertEquals ($ value , $ instance ->get ($ key ));
218
-
219
211
}
220
212
}
0 commit comments