|
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
|
|
|
*/ |
|
447
|
|
|
public function testGetCachedScriptsZeroedTimestamp() |
|
448
|
|
|
{ |
|
449
|
|
|
$statusData = $this->statusData; |
|
450
|
|
|
|
|
451
|
|
|
$statusData['scripts'] = [ |
|
452
|
|
|
[ |
|
453
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
|
454
|
|
|
'hits' => 1, |
|
455
|
|
|
'memory_consumption' => 6608, |
|
456
|
|
|
'last_used' => 'Thu Oct 09 16:08:35 2014', |
|
457
|
|
|
'last_used_timestamp' => 1412863715, |
|
458
|
|
|
'timestamp' => 0, |
|
459
|
|
|
], |
|
460
|
|
|
]; |
|
461
|
|
|
|
|
462
|
|
|
$status = new Status( |
|
463
|
|
|
$this->getMock('\\OpCacheGUI\\Format\\Byte'), |
|
464
|
|
|
$this->getMock('\\OpCacheGUI\\I18n\\Translator'), |
|
465
|
|
|
$statusData |
|
466
|
|
|
); |
|
467
|
|
|
|
|
468
|
|
|
$this->assertSame([], $status->getCachedScripts()); |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
/** |
|
472
|
|
|
* @covers OpCacheGUI\OpCache\Status::__construct |
|
473
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScriptsForOverview |
|
474
|
|
|
* @covers OpCacheGUI\OpCache\Status::getCachedScripts |
|
475
|
|
|
* @covers OpCacheGUI\OpCache\Status::sortCachedScripts |
|
476
|
|
|
*/ |
|
477
|
|
|
public function testGetCachedScriptsForOverviewFilled() |
|
478
|
|
|
{ |
|
479
|
|
|
$formatter = $this->getMock('\\OpCacheGUI\\Format\\Byte'); |
|
480
|
|
|
$formatter->method('format')->will($this->onConsecutiveCalls('1KB', '2KB', '3KB', '4KB', '5KB', '6KB')); |
|
481
|
|
|
|
|
482
|
|
|
$status = new Status($formatter, $this->getMock('\\OpCacheGUI\\I18n\\Translator'), $this->statusData); |
|
483
|
|
|
|
|
484
|
|
|
$data = [ |
|
485
|
|
|
[ |
|
486
|
|
|
'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php', |
|
487
|
|
|
'hits' => 12876, |
|
488
|
|
|
'memory_consumption' => '6KB', |
|
489
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
|
490
|
|
|
'timestamp' => 'N/A', |
|
491
|
|
|
], |
|
492
|
|
|
[ |
|
493
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
|
494
|
|
|
'hits' => 1, |
|
495
|
|
|
'memory_consumption' => '1KB', |
|
496
|
|
|
'last_used_timestamp' => '14:08:35 09-10-2014', |
|
497
|
|
|
'timestamp' => '16:20:53 07-10-2014', |
|
498
|
|
|
], |
|
499
|
|
|
[ |
|
500
|
|
|
'full_path' => '/var/www/vhosts/OpcacheGUI/template/cached.phtml', |
|
501
|
|
|
'hits' => 4, |
|
502
|
|
|
'memory_consumption' => '2KB', |
|
503
|
|
|
'last_used_timestamp' => '14:08:35 09-10-2014', |
|
504
|
|
|
'timestamp' => '16:20:53 07-10-2014', |
|
505
|
|
|
], |
|
506
|
|
|
[ |
|
507
|
|
|
'full_path' => '/var/www/vhosts/RedTube/template/humiliation/germany-vs-brazil.phtml', |
|
508
|
|
|
'hits' => 71, |
|
509
|
|
|
'memory_consumption' => '4KB', |
|
510
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
|
511
|
|
|
'timestamp' => '20:01:15 08-10-2014', |
|
512
|
|
|
], |
|
513
|
|
|
[ |
|
514
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php', |
|
515
|
|
|
'hits' => 19, |
|
516
|
|
|
'memory_consumption' => '3KB', |
|
517
|
|
|
'last_used_timestamp' => '15:31:55 09-10-2014', |
|
518
|
|
|
'timestamp' => '20:07:33 08-10-2014', |
|
519
|
|
|
], |
|
520
|
|
|
[ |
|
521
|
|
|
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Psr/Autoloader.php', |
|
522
|
|
|
'hits' => 32, |
|
523
|
|
|
'memory_consumption' => '5KB', |
|
524
|
|
|
'last_used_timestamp' => '14:25:15 09-10-2014', |
|
525
|
|
|
'timestamp' => '20:01:15 08-10-2014', |
|
526
|
|
|
], |
|
527
|
|
|
]; |
|
528
|
|
|
|
|
529
|
|
|
$trimmer = $this->getMock('\\OpCacheGUI\\Format\\Trimmer'); |
|
530
|
|
|
$trimmer->method('trim')->will($this->returnArgument(0)); |
|
531
|
|
|
|
|
532
|
|
|
$this->assertSame($data, $status->getCachedScriptsForOverview($trimmer)); |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
|
|
} |
|
536
|
|
|
|