1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpCacheGUITest\OpCache; |
4
|
|
|
|
5
|
|
|
use OpCacheGUI\OpCache\Status; |
6
|
|
|
|
7
|
|
|
class StatusTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
protected $statusData; |
10
|
|
|
|
11
|
|
|
protected function setUp() |
12
|
|
|
{ |
13
|
|
|
date_default_timezone_set('UTC'); |
14
|
|
|
|
15
|
|
|
$this->statusData = [ |
16
|
|
|
'opcache_enabled' => true, |
17
|
|
|
'cache_full' => false, |
18
|
|
|
'restart_pending' => false, |
19
|
|
|
'restart_in_progress' => false, |
20
|
|
|
'memory_usage' => [ |
21
|
|
|
'used_memory' => '457392', |
22
|
|
|
'free_memory' => '133573736', |
23
|
|
|
'wasted_memory' => '186600', |
24
|
|
|
'current_wasted_percentage' => '0.1390278339386', |
25
|
|
|
], |
26
|
|
|
'opcache_statistics' => [ |
27
|
|
|
'num_cached_scripts' => 38, |
28
|
|
|
'num_cached_keys' => 52, |
29
|
|
|
'max_cached_keys' => 7963, |
30
|
|
|
'hits' => 1160, |
31
|
|
|
'misses' => 59, |
32
|
|
|
'blacklist_misses' => 0, |
33
|
|
|
'blacklist_miss_ratio' => 0, |
34
|
|
|
'opcache_hit_rate' => 95.159967186218, |
35
|
|
|
'start_time' => 1412775693, |
36
|
|
|
'last_restart_time' => 1412790000, |
37
|
|
|
'oom_restarts' => 0, |
38
|
|
|
'hash_restarts' => 0, |
39
|
|
|
'manual_restarts' => 0, |
40
|
|
|
], |
41
|
|
|
'scripts' => [ |
42
|
|
|
[ |
43
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
44
|
|
|
'hits' => 1, |
45
|
|
|
'memory_consumption' => 6608, |
46
|
|
|
'last_used' => 'Thu Oct 09 16:08:35 2014', |
47
|
|
|
'last_used_timestamp' => 1412863715, |
48
|
|
|
'timestamp' => 1412698853, |
49
|
|
|
], |
50
|
|
|
[ |
51
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/template/cached.phtml', |
52
|
|
|
'hits' => 4, |
53
|
|
|
'memory_consumption' => 3213, |
54
|
|
|
'last_used' => 'Thu Oct 09 16:06:35 2014', |
55
|
|
|
'last_used_timestamp' => 1412863715, |
56
|
|
|
'timestamp' => 1412698853, |
57
|
|
|
], |
58
|
|
|
[ |
59
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php', |
60
|
|
|
'hits' => 19, |
61
|
|
|
'memory_consumption' => 204, |
62
|
|
|
'last_used' => 'Thu Oct 09 16:04:35 2014', |
63
|
|
|
'last_used_timestamp' => 1412868715, |
64
|
|
|
'timestamp' => 1412798853, |
65
|
|
|
], |
66
|
|
|
[ |
67
|
|
|
'full_path' => '/var/www/vhosts/RedTube/template/humiliation/germany-vs-brazil.phtml', |
68
|
|
|
'hits' => 71, |
69
|
|
|
'memory_consumption' => 7001, |
70
|
|
|
'last_used' => 'Thu Jul 09 21:20:10 2014', |
71
|
|
|
'last_used_timestamp' => 1412864715, |
72
|
|
|
'timestamp' => 1412798475, |
73
|
|
|
], |
74
|
|
|
[ |
75
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Psr/Autoloader.php', |
76
|
|
|
'hits' => 32, |
77
|
|
|
'memory_consumption' => 4678, |
78
|
|
|
'last_used' => 'Thu Oct 10 15:04:35 2014', |
79
|
|
|
'last_used_timestamp' => 1412864715, |
80
|
|
|
'timestamp' => 1412798475, |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php', |
84
|
|
|
'hits' => 12876, |
85
|
|
|
'memory_consumption' => 2048, |
86
|
|
|
'last_used' => 'Thu Oct 10 15:04:35 2014', |
87
|
|
|
'last_used_timestamp' => 1412864715, |
88
|
|
|
], |
89
|
|
|
], |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
95
|
|
|
* @covers OpCacheGUI\OpCache\Status::getStatusInfo |
96
|
|
|
*/ |
97
|
|
|
public function testGetStatusInfo() |
98
|
|
|
{ |
99
|
|
|
$status = new Status( |
100
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
101
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
102
|
|
|
$this->statusData |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$data = []; |
106
|
|
|
|
107
|
|
|
foreach ($this->statusData as $key => $value) { |
108
|
|
|
if (!in_array($key, ['opcache_enabled', 'cache_full', 'restart_pending', 'restart_in_progress'], true)) { |
109
|
|
|
continue; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$data[$key] = $value; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$this->assertSame($data, $status->getStatusInfo()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
120
|
|
|
* @covers OpCacheGUI\OpCache\Status::getMemoryInfo |
121
|
|
|
*/ |
122
|
|
|
public function testGetMemoryInfo() |
123
|
|
|
{ |
124
|
|
|
$formatter = $this->getMock('\\OpCacheGUI\\Format\\Byte'); |
125
|
|
|
$formatter->method('format')->will($this->onConsecutiveCalls('1KB', '2KB', '3KB')); |
126
|
|
|
|
127
|
|
|
$status = new Status($formatter, $this->getMock('\\OpCacheGUI\\I18n\\Translator'), $this->statusData); |
128
|
|
|
|
129
|
|
|
$data = $this->statusData; |
130
|
|
|
|
131
|
|
|
$data['memory_usage']['used_memory'] = '1KB'; |
132
|
|
|
$data['memory_usage']['free_memory'] = '2KB'; |
133
|
|
|
$data['memory_usage']['wasted_memory'] = '3KB'; |
134
|
|
|
$data['memory_usage']['current_wasted_percentage'] = '0.14%'; |
135
|
|
|
|
136
|
|
|
$this->assertSame($data['memory_usage'], $status->getMemoryInfo()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
141
|
|
|
* @covers OpCacheGUI\OpCache\Status::getGraphMemoryInfo |
142
|
|
|
*/ |
143
|
|
|
public function testGetGraphMemoryInfo() |
144
|
|
|
{ |
145
|
|
|
$translator = $this->getMock('\\OpCacheGUI\\I18n\\Translator'); |
146
|
|
|
$translator->method('translate')->will($this->onConsecutiveCalls('Used', 'Free', 'Wasted')); |
147
|
|
|
|
148
|
|
|
$status = new Status( |
149
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
150
|
|
|
$translator, |
151
|
|
|
$this->statusData |
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
$data = [ |
155
|
|
|
[ |
156
|
|
|
'value' => $this->statusData['memory_usage']['used_memory'], |
157
|
|
|
'color' => '#16a085', |
158
|
|
|
'label' => 'Used', |
159
|
|
|
], |
160
|
|
|
[ |
161
|
|
|
'value' => $this->statusData['memory_usage']['free_memory'], |
162
|
|
|
'color' => '#2ecc71', |
163
|
|
|
'label' => 'Free', |
164
|
|
|
], |
165
|
|
|
[ |
166
|
|
|
'value' => $this->statusData['memory_usage']['wasted_memory'], |
167
|
|
|
'color' => '#e74c3c', |
168
|
|
|
'label' => 'Wasted', |
169
|
|
|
], |
170
|
|
|
]; |
171
|
|
|
|
172
|
|
|
$this->assertSame(json_encode($data), $status->getGraphMemoryInfo()); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
177
|
|
|
* @covers OpCacheGUI\OpCache\Status::getStatsInfo |
178
|
|
|
*/ |
179
|
|
|
public function testGetStatsInfoWithOpCacheDisabled() |
180
|
|
|
{ |
181
|
|
|
$statusData = $this->statusData; |
182
|
|
|
$statusData['opcache_enabled'] = false; |
183
|
|
|
|
184
|
|
|
$status = new Status( |
185
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
186
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
187
|
|
|
$statusData |
188
|
|
|
); |
189
|
|
|
|
190
|
|
|
$data = [ |
191
|
|
|
[ |
192
|
|
|
'num_cached_scripts' => 0, |
193
|
|
|
'num_cached_keys' => 0, |
194
|
|
|
'max_cached_keys' => 0, |
195
|
|
|
'hits' => 0, |
196
|
|
|
'misses' => 0, |
197
|
|
|
'blacklist_misses' => 0, |
198
|
|
|
'blacklist_miss_ratio' => 'n/a', |
199
|
|
|
], |
200
|
|
|
[ |
201
|
|
|
'opcache_hit_rate' => 'n/a', |
202
|
|
|
'start_time' => 'n/a', |
203
|
|
|
'last_restart_time' => 'n/a', |
204
|
|
|
'oom_restarts' => 'n/a', |
205
|
|
|
'hash_restarts' => 'n/a', |
206
|
|
|
'manual_restarts' => 'n/a', |
207
|
|
|
] |
208
|
|
|
]; |
209
|
|
|
|
210
|
|
|
$this->assertSame($data, $status->getStatsInfo()); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
215
|
|
|
* @covers OpCacheGUI\OpCache\Status::getStatsInfo |
216
|
|
|
*/ |
217
|
|
|
public function testGetStatsInfoWithOpCacheEnabled() |
218
|
|
|
{ |
219
|
|
|
$status = new Status( |
220
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
221
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
222
|
|
|
$this->statusData |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
$data = $this->statusData['opcache_statistics']; |
226
|
|
|
|
227
|
|
|
$data['blacklist_miss_ratio'] = 0.0; |
228
|
|
|
$data['opcache_hit_rate'] = '95.16%'; |
229
|
|
|
$data['start_time'] = '13:41:33 08-10-2014'; |
230
|
|
|
$data['last_restart_time'] = '17:40:00 08-10-2014'; |
231
|
|
|
|
232
|
|
|
$formattedData = [ |
233
|
|
|
array_slice($data, 0, 7, true), |
234
|
|
|
array_slice($data, 7, null, true), |
235
|
|
|
]; |
236
|
|
|
|
237
|
|
|
$this->assertSame($formattedData, $status->getStatsInfo()); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
242
|
|
|
* @covers OpCacheGUI\OpCache\Status::getStatsInfo |
243
|
|
|
*/ |
244
|
|
|
public function testGetStatsInfoWithOpCacheEnabledTakesIntoAccountTimeZones() |
245
|
|
|
{ |
246
|
|
|
date_default_timezone_set('Europe/Amsterdam'); |
247
|
|
|
|
248
|
|
|
$status = new Status( |
249
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
250
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
251
|
|
|
$this->statusData |
252
|
|
|
); |
253
|
|
|
|
254
|
|
|
$data = $this->statusData['opcache_statistics']; |
255
|
|
|
|
256
|
|
|
$data['blacklist_miss_ratio'] = 0.0; |
257
|
|
|
$data['opcache_hit_rate'] = '95.16%'; |
258
|
|
|
$data['start_time'] = '15:41:33 08-10-2014'; |
259
|
|
|
$data['last_restart_time'] = '19:40:00 08-10-2014'; |
260
|
|
|
|
261
|
|
|
$formattedData = [ |
262
|
|
|
array_slice($data, 0, 7, true), |
263
|
|
|
array_slice($data, 7, null, true), |
264
|
|
|
]; |
265
|
|
|
|
266
|
|
|
$this->assertSame($formattedData, $status->getStatsInfo()); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
271
|
|
|
* @covers OpCacheGUI\OpCache\Status::getStatsInfo |
272
|
|
|
*/ |
273
|
|
|
public function testGetStatsInfoWithOpCacheEnabledWithoutRestart() |
274
|
|
|
{ |
275
|
|
|
$statusData = $this->statusData; |
276
|
|
|
|
277
|
|
|
$statusData['opcache_statistics']['last_restart_time'] = 0; |
278
|
|
|
|
279
|
|
|
$status = new Status( |
280
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
281
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
282
|
|
|
$statusData |
283
|
|
|
); |
284
|
|
|
|
285
|
|
|
$data = $this->statusData['opcache_statistics']; |
286
|
|
|
|
287
|
|
|
$data['blacklist_miss_ratio'] = 0.0; |
288
|
|
|
$data['opcache_hit_rate'] = '95.16%'; |
289
|
|
|
$data['start_time'] = '13:41:33 08-10-2014'; |
290
|
|
|
$data['last_restart_time'] = null; |
291
|
|
|
|
292
|
|
|
$formattedData = [ |
293
|
|
|
array_slice($data, 0, 7, true), |
294
|
|
|
array_slice($data, 7, null, true), |
295
|
|
|
]; |
296
|
|
|
|
297
|
|
|
$this->assertSame($formattedData, $status->getStatsInfo()); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
302
|
|
|
* @covers OpCacheGUI\OpCache\Status::getGraphKeyStatsInfo |
303
|
|
|
*/ |
304
|
|
|
public function testGetGraphKeyStatsInfo() |
305
|
|
|
{ |
306
|
|
|
$translator = $this->getMock('\\OpCacheGUI\\I18n\\Translator'); |
307
|
|
|
$translator->method('translate')->will($this->onConsecutiveCalls('Used', 'Free', 'Wasted')); |
308
|
|
|
|
309
|
|
|
$status = new Status($this->getMock('\\OpCacheGUI\\Format\\Byte'), $translator, $this->statusData); |
310
|
|
|
|
311
|
|
|
$data = [ |
312
|
|
|
[ |
313
|
|
|
'value' => 38, |
314
|
|
|
'color' => '#16a085', |
315
|
|
|
'label' => 'Used', |
316
|
|
|
], |
317
|
|
|
[ |
318
|
|
|
'value' => 7911, |
319
|
|
|
'color' => '#2ecc71', |
320
|
|
|
'label' => 'Free', |
321
|
|
|
], |
322
|
|
|
[ |
323
|
|
|
'value' => 14, |
324
|
|
|
'color' => '#e74c3c', |
325
|
|
|
'label' => 'Wasted', |
326
|
|
|
], |
327
|
|
|
]; |
328
|
|
|
|
329
|
|
|
$this->assertSame(json_encode($data), $status->getGraphKeyStatsInfo()); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
334
|
|
|
* @covers OpCacheGUI\OpCache\Status::getGraphHitStatsInfo |
335
|
|
|
*/ |
336
|
|
|
public function testGetGraphHitStatsInfo() |
337
|
|
|
{ |
338
|
|
|
$translator = $this->getMock('\\OpCacheGUI\\I18n\\Translator'); |
339
|
|
|
$translator->method('translate')->will($this->onConsecutiveCalls('Hits', 'Misses', 'Blacklisted')); |
340
|
|
|
|
341
|
|
|
$status = new Status($this->getMock('\\OpCacheGUI\\Format\\Byte'), $translator, $this->statusData); |
342
|
|
|
|
343
|
|
|
$data = [ |
344
|
|
|
[ |
345
|
|
|
'value' => 1160, |
346
|
|
|
'color' => '#2ecc71', |
347
|
|
|
'label' => 'Hits', |
348
|
|
|
], |
349
|
|
|
[ |
350
|
|
|
'value' => 59, |
351
|
|
|
'color' => '#e74c3c', |
352
|
|
|
'label' => 'Misses', |
353
|
|
|
], |
354
|
|
|
[ |
355
|
|
|
'value' => 0, |
356
|
|
|
'color' => '#16a085', |
357
|
|
|
'label' => 'Blacklisted', |
358
|
|
|
], |
359
|
|
|
]; |
360
|
|
|
|
361
|
|
|
$this->assertSame(json_encode($data), $status->getGraphHitStatsInfo()); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
366
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScripts |
367
|
|
|
*/ |
368
|
|
|
public function testGetCachedScriptsEmpty() |
369
|
|
|
{ |
370
|
|
|
$statusData = $this->statusData; |
371
|
|
|
|
372
|
|
|
unset($statusData['scripts']); |
373
|
|
|
|
374
|
|
|
$status = new Status( |
375
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
376
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
377
|
|
|
$statusData |
378
|
|
|
); |
379
|
|
|
|
380
|
|
|
$this->assertSame([], $status->getCachedScripts()); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
385
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScripts |
386
|
|
|
* @covers OpCacheGUI\OpCache\Status::sortCachedScripts |
387
|
|
|
*/ |
388
|
|
|
public function testGetCachedScriptsFilled() |
389
|
|
|
{ |
390
|
|
|
$formatter = $this->getMock('\\OpCacheGUI\\Format\\Byte'); |
391
|
|
|
$formatter->method('format')->will($this->onConsecutiveCalls('1KB', '2KB', '3KB', '4KB', '5KB', '6KB')); |
392
|
|
|
|
393
|
|
|
$status = new Status($formatter, $this->getMock('\\OpCacheGUI\\I18n\\Translator'), $this->statusData); |
394
|
|
|
|
395
|
|
|
$data = [ |
396
|
|
|
[ |
397
|
|
|
'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php', |
398
|
|
|
'hits' => 12876, |
399
|
|
|
'memory_consumption' => '6KB', |
400
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
401
|
|
|
'timestamp' => 'N/A', |
402
|
|
|
], |
403
|
|
|
[ |
404
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
405
|
|
|
'hits' => 1, |
406
|
|
|
'memory_consumption' => '1KB', |
407
|
|
|
'last_used_timestamp' => '14:08:35 09-10-2014', |
408
|
|
|
'timestamp' => '16:20:53 07-10-2014', |
409
|
|
|
], |
410
|
|
|
[ |
411
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/template/cached.phtml', |
412
|
|
|
'hits' => 4, |
413
|
|
|
'memory_consumption' => '2KB', |
414
|
|
|
'last_used_timestamp' => '14:08:35 09-10-2014', |
415
|
|
|
'timestamp' => '16:20:53 07-10-2014', |
416
|
|
|
], |
417
|
|
|
[ |
418
|
|
|
'full_path' => '/var/www/vhosts/RedTube/template/humiliation/germany-vs-brazil.phtml', |
419
|
|
|
'hits' => 71, |
420
|
|
|
'memory_consumption' => '4KB', |
421
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
422
|
|
|
'timestamp' => '20:01:15 08-10-2014', |
423
|
|
|
], |
424
|
|
|
[ |
425
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php', |
426
|
|
|
'hits' => 19, |
427
|
|
|
'memory_consumption' => '3KB', |
428
|
|
|
'last_used_timestamp' => '15:31:55 09-10-2014', |
429
|
|
|
'timestamp' => '20:07:33 08-10-2014', |
430
|
|
|
], |
431
|
|
|
[ |
432
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Psr/Autoloader.php', |
433
|
|
|
'hits' => 32, |
434
|
|
|
'memory_consumption' => '5KB', |
435
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
436
|
|
|
'timestamp' => '20:01:15 08-10-2014', |
437
|
|
|
], |
438
|
|
|
]; |
439
|
|
|
|
440
|
|
|
$this->assertSame($data, $status->getCachedScripts()); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
445
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScripts |
446
|
|
|
* @covers OpCacheGUI\OpCache\Status::sortCachedScripts |
447
|
|
|
*/ |
448
|
|
|
public function testGetCachedScriptsFilledTakesIntoAccountTimeZones() |
449
|
|
|
{ |
450
|
|
|
date_default_timezone_set('Europe/Amsterdam'); |
451
|
|
|
|
452
|
|
|
$formatter = $this->getMock('\\OpCacheGUI\\Format\\Byte'); |
453
|
|
|
$formatter->method('format')->will($this->onConsecutiveCalls('1KB', '2KB', '3KB', '4KB', '5KB', '6KB')); |
454
|
|
|
|
455
|
|
|
$status = new Status($formatter, $this->getMock('\\OpCacheGUI\\I18n\\Translator'), $this->statusData); |
456
|
|
|
|
457
|
|
|
$data = [ |
458
|
|
|
[ |
459
|
|
|
'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php', |
460
|
|
|
'hits' => 12876, |
461
|
|
|
'memory_consumption' => '6KB', |
462
|
|
|
'last_used_timestamp' => '16:25:15 09-10-2014', |
463
|
|
|
'timestamp' => 'N/A', |
464
|
|
|
], |
465
|
|
|
[ |
466
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
467
|
|
|
'hits' => 1, |
468
|
|
|
'memory_consumption' => '1KB', |
469
|
|
|
'last_used_timestamp' => '16:08:35 09-10-2014', |
470
|
|
|
'timestamp' => '18:20:53 07-10-2014', |
471
|
|
|
], |
472
|
|
|
[ |
473
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/template/cached.phtml', |
474
|
|
|
'hits' => 4, |
475
|
|
|
'memory_consumption' => '2KB', |
476
|
|
|
'last_used_timestamp' => '16:08:35 09-10-2014', |
477
|
|
|
'timestamp' => '18:20:53 07-10-2014', |
478
|
|
|
], |
479
|
|
|
[ |
480
|
|
|
'full_path' => '/var/www/vhosts/RedTube/template/humiliation/germany-vs-brazil.phtml', |
481
|
|
|
'hits' => 71, |
482
|
|
|
'memory_consumption' => '4KB', |
483
|
|
|
'last_used_timestamp' => '16:25:15 09-10-2014', |
484
|
|
|
'timestamp' => '22:01:15 08-10-2014', |
485
|
|
|
], |
486
|
|
|
[ |
487
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php', |
488
|
|
|
'hits' => 19, |
489
|
|
|
'memory_consumption' => '3KB', |
490
|
|
|
'last_used_timestamp' => '17:31:55 09-10-2014', |
491
|
|
|
'timestamp' => '22:07:33 08-10-2014', |
492
|
|
|
], |
493
|
|
|
[ |
494
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Psr/Autoloader.php', |
495
|
|
|
'hits' => 32, |
496
|
|
|
'memory_consumption' => '5KB', |
497
|
|
|
'last_used_timestamp' => '16:25:15 09-10-2014', |
498
|
|
|
'timestamp' => '22:01:15 08-10-2014', |
499
|
|
|
], |
500
|
|
|
]; |
501
|
|
|
|
502
|
|
|
$this->assertSame($data, $status->getCachedScripts()); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
507
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScripts |
508
|
|
|
*/ |
509
|
|
|
public function testGetCachedScriptsZeroedTimestamp() |
510
|
|
|
{ |
511
|
|
|
$statusData = $this->statusData; |
512
|
|
|
|
513
|
|
|
$statusData['scripts'] = [ |
514
|
|
|
[ |
515
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
516
|
|
|
'hits' => 1, |
517
|
|
|
'memory_consumption' => 6608, |
518
|
|
|
'last_used' => 'Thu Oct 09 16:08:35 2014', |
519
|
|
|
'last_used_timestamp' => 1412863715, |
520
|
|
|
'timestamp' => 0, |
521
|
|
|
], |
522
|
|
|
]; |
523
|
|
|
|
524
|
|
|
$status = new Status( |
525
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
526
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
527
|
|
|
$statusData |
528
|
|
|
); |
529
|
|
|
|
530
|
|
|
$this->assertSame([], $status->getCachedScripts()); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
535
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScriptsForOverview |
536
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScripts |
537
|
|
|
* @covers OpCacheGUI\OpCache\Status::sortCachedScripts |
538
|
|
|
*/ |
539
|
|
|
public function testGetCachedScriptsForOverviewFilled() |
540
|
|
|
{ |
541
|
|
|
$formatter = $this->getMock('\\OpCacheGUI\\Format\\Byte'); |
542
|
|
|
$formatter->method('format')->will($this->onConsecutiveCalls('1KB', '2KB', '3KB', '4KB', '5KB', '6KB')); |
543
|
|
|
|
544
|
|
|
$status = new Status($formatter, $this->getMock('\\OpCacheGUI\\I18n\\Translator'), $this->statusData); |
545
|
|
|
|
546
|
|
|
$data = [ |
547
|
|
|
[ |
548
|
|
|
'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php', |
549
|
|
|
'hits' => 12876, |
550
|
|
|
'memory_consumption' => '6KB', |
551
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
552
|
|
|
'timestamp' => 'N/A', |
553
|
|
|
], |
554
|
|
|
[ |
555
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
556
|
|
|
'hits' => 1, |
557
|
|
|
'memory_consumption' => '1KB', |
558
|
|
|
'last_used_timestamp' => '14:08:35 09-10-2014', |
559
|
|
|
'timestamp' => '16:20:53 07-10-2014', |
560
|
|
|
], |
561
|
|
|
[ |
562
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/template/cached.phtml', |
563
|
|
|
'hits' => 4, |
564
|
|
|
'memory_consumption' => '2KB', |
565
|
|
|
'last_used_timestamp' => '14:08:35 09-10-2014', |
566
|
|
|
'timestamp' => '16:20:53 07-10-2014', |
567
|
|
|
], |
568
|
|
|
[ |
569
|
|
|
'full_path' => '/var/www/vhosts/RedTube/template/humiliation/germany-vs-brazil.phtml', |
570
|
|
|
'hits' => 71, |
571
|
|
|
'memory_consumption' => '4KB', |
572
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
573
|
|
|
'timestamp' => '20:01:15 08-10-2014', |
574
|
|
|
], |
575
|
|
|
[ |
576
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php', |
577
|
|
|
'hits' => 19, |
578
|
|
|
'memory_consumption' => '3KB', |
579
|
|
|
'last_used_timestamp' => '15:31:55 09-10-2014', |
580
|
|
|
'timestamp' => '20:07:33 08-10-2014', |
581
|
|
|
], |
582
|
|
|
[ |
583
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Psr/Autoloader.php', |
584
|
|
|
'hits' => 32, |
585
|
|
|
'memory_consumption' => '5KB', |
586
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
587
|
|
|
'timestamp' => '20:01:15 08-10-2014', |
588
|
|
|
], |
589
|
|
|
]; |
590
|
|
|
|
591
|
|
|
$trimmer = $this->getMock('\\OpCacheGUI\\Format\\Trimmer'); |
592
|
|
|
$trimmer->method('trim')->will($this->returnArgument(0)); |
593
|
|
|
|
594
|
|
|
$this->assertSame($data, $status->getCachedScriptsForOverview($trimmer)); |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
} |
598
|
|
|
|