1 | <?php |
||
11 | class StatusTest extends TestCase |
||
12 | { |
||
13 | protected $statusData; |
||
14 | |||
15 | protected function setUp() |
||
96 | |||
97 | /** |
||
98 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
99 | * @covers OpCacheGUI\OpCache\Status::getStatusInfo |
||
100 | */ |
||
101 | public function testGetStatusInfo() |
||
121 | |||
122 | /** |
||
123 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
124 | * @covers OpCacheGUI\OpCache\Status::getMemoryInfo |
||
125 | */ |
||
126 | public function testGetMemoryInfo() |
||
142 | |||
143 | /** |
||
144 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
145 | * @covers OpCacheGUI\OpCache\Status::getGraphMemoryInfo |
||
146 | */ |
||
147 | public function testGetGraphMemoryInfo() |
||
148 | { |
||
149 | $translator = $this->createMock(Translator::class); |
||
150 | $translator->method('translate')->will($this->onConsecutiveCalls('Used', 'Free', 'Wasted')); |
||
151 | |||
152 | $status = new Status( |
||
153 | $this->createMock(Byte::class), |
||
154 | $translator, |
||
155 | $this->statusData |
||
156 | ); |
||
157 | |||
158 | $data = [ |
||
159 | [ |
||
160 | 'value' => $this->statusData['memory_usage']['used_memory'], |
||
161 | 'color' => '#16a085', |
||
162 | 'label' => 'Used', |
||
163 | ], |
||
164 | [ |
||
165 | 'value' => $this->statusData['memory_usage']['free_memory'], |
||
166 | 'color' => '#2ecc71', |
||
167 | 'label' => 'Free', |
||
168 | ], |
||
169 | [ |
||
170 | 'value' => $this->statusData['memory_usage']['wasted_memory'], |
||
171 | 'color' => '#e74c3c', |
||
172 | 'label' => 'Wasted', |
||
173 | ], |
||
174 | ]; |
||
175 | |||
176 | $this->assertSame(json_encode($data), $status->getGraphMemoryInfo()); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
181 | * @covers OpCacheGUI\OpCache\Status::getStatsInfo |
||
182 | */ |
||
183 | public function testGetStatsInfoWithOpCacheDisabled() |
||
216 | |||
217 | /** |
||
218 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
219 | * @covers OpCacheGUI\OpCache\Status::getStatsInfo |
||
220 | */ |
||
221 | public function testGetStatsInfoWithOpCacheEnabled() |
||
243 | |||
244 | /** |
||
245 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
246 | * @covers OpCacheGUI\OpCache\Status::getStatsInfo |
||
247 | */ |
||
248 | public function testGetStatsInfoWithOpCacheEnabledTakesIntoAccountTimeZones() |
||
272 | |||
273 | /** |
||
274 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
275 | * @covers OpCacheGUI\OpCache\Status::getStatsInfo |
||
276 | */ |
||
277 | public function testGetStatsInfoWithOpCacheEnabledWithoutRestart() |
||
303 | |||
304 | /** |
||
305 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
306 | * @covers OpCacheGUI\OpCache\Status::getGraphKeyStatsInfo |
||
307 | */ |
||
308 | public function testGetGraphKeyStatsInfo() |
||
309 | { |
||
310 | $translator = $this->createMock(Translator::class); |
||
311 | $translator->method('translate')->will($this->onConsecutiveCalls('Used', 'Free', 'Wasted')); |
||
312 | |||
313 | $status = new Status($this->createMock(Byte::class), $translator, $this->statusData); |
||
314 | |||
315 | $data = [ |
||
316 | [ |
||
317 | 'value' => 38, |
||
318 | 'color' => '#16a085', |
||
319 | 'label' => 'Used', |
||
320 | ], |
||
321 | [ |
||
322 | 'value' => 7911, |
||
323 | 'color' => '#2ecc71', |
||
324 | 'label' => 'Free', |
||
325 | ], |
||
326 | [ |
||
327 | 'value' => 14, |
||
328 | 'color' => '#e74c3c', |
||
329 | 'label' => 'Wasted', |
||
330 | ], |
||
331 | ]; |
||
332 | |||
333 | $this->assertSame(json_encode($data), $status->getGraphKeyStatsInfo()); |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
338 | * @covers OpCacheGUI\OpCache\Status::getGraphHitStatsInfo |
||
339 | */ |
||
340 | public function testGetGraphHitStatsInfo() |
||
341 | { |
||
342 | $translator = $this->createMock(Translator::class); |
||
343 | $translator->method('translate')->will($this->onConsecutiveCalls('Hits', 'Misses', 'Blacklisted')); |
||
344 | |||
345 | $status = new Status($this->createMock(Byte::class), $translator, $this->statusData); |
||
346 | |||
347 | $data = [ |
||
348 | [ |
||
349 | 'value' => 1160, |
||
350 | 'color' => '#2ecc71', |
||
351 | 'label' => 'Hits', |
||
352 | ], |
||
353 | [ |
||
354 | 'value' => 59, |
||
355 | 'color' => '#e74c3c', |
||
356 | 'label' => 'Misses', |
||
357 | ], |
||
358 | [ |
||
359 | 'value' => 0, |
||
360 | 'color' => '#16a085', |
||
361 | 'label' => 'Blacklisted', |
||
362 | ], |
||
363 | ]; |
||
364 | |||
365 | $this->assertSame(json_encode($data), $status->getGraphHitStatsInfo()); |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
370 | * @covers OpCacheGUI\OpCache\Status::getCachedScripts |
||
371 | */ |
||
372 | public function testGetCachedScriptsEmpty() |
||
386 | |||
387 | /** |
||
388 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
389 | * @covers OpCacheGUI\OpCache\Status::getCachedScripts |
||
390 | * @covers OpCacheGUI\OpCache\Status::sortCachedScripts |
||
391 | */ |
||
392 | public function testGetCachedScriptsFilled() |
||
446 | |||
447 | /** |
||
448 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
449 | * @covers OpCacheGUI\OpCache\Status::getCachedScripts |
||
450 | * @covers OpCacheGUI\OpCache\Status::sortCachedScripts |
||
451 | */ |
||
452 | public function testGetCachedScriptsFilledTakesIntoAccountTimeZones() |
||
453 | { |
||
454 | date_default_timezone_set('Europe/Amsterdam'); |
||
455 | |||
456 | $formatter = $this->createMock(Byte::class); |
||
457 | $formatter->method('format')->will($this->onConsecutiveCalls('1KB', '2KB', '3KB', '4KB', '5KB', '6KB')); |
||
458 | |||
459 | $status = new Status($formatter, $this->createMock(Translator::class), $this->statusData); |
||
460 | |||
461 | $data = [ |
||
462 | [ |
||
463 | 'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php', |
||
464 | 'hits' => 12876, |
||
465 | 'memory_consumption' => '6KB', |
||
466 | 'last_used_timestamp' => '16:25:15 09-10-2014', |
||
467 | 'timestamp' => 'N/A', |
||
468 | ], |
||
469 | [ |
||
470 | 'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php', |
||
471 | 'hits' => 1, |
||
472 | 'memory_consumption' => '1KB', |
||
473 | 'last_used_timestamp' => '16:08:35 09-10-2014', |
||
474 | 'timestamp' => '18:20:53 07-10-2014', |
||
475 | ], |
||
476 | [ |
||
477 | 'full_path' => '/var/www/vhosts/OpcacheGUI/template/cached.phtml', |
||
478 | 'hits' => 4, |
||
479 | 'memory_consumption' => '2KB', |
||
480 | 'last_used_timestamp' => '16:08:35 09-10-2014', |
||
481 | 'timestamp' => '18:20:53 07-10-2014', |
||
482 | ], |
||
483 | [ |
||
484 | 'full_path' => '/var/www/vhosts/RedTube/template/humiliation/germany-vs-brazil.phtml', |
||
485 | 'hits' => 71, |
||
486 | 'memory_consumption' => '4KB', |
||
487 | 'last_used_timestamp' => '16:25:15 09-10-2014', |
||
488 | 'timestamp' => '22:01:15 08-10-2014', |
||
489 | ], |
||
490 | [ |
||
491 | 'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php', |
||
492 | 'hits' => 19, |
||
493 | 'memory_consumption' => '3KB', |
||
494 | 'last_used_timestamp' => '17:31:55 09-10-2014', |
||
495 | 'timestamp' => '22:07:33 08-10-2014', |
||
496 | ], |
||
497 | [ |
||
498 | 'full_path' => '/var/www/vhosts/SomeOtherProject/src/Psr/Autoloader.php', |
||
499 | 'hits' => 32, |
||
500 | 'memory_consumption' => '5KB', |
||
501 | 'last_used_timestamp' => '16:25:15 09-10-2014', |
||
502 | 'timestamp' => '22:01:15 08-10-2014', |
||
503 | ], |
||
504 | ]; |
||
505 | |||
506 | $this->assertSame($data, $status->getCachedScripts()); |
||
507 | } |
||
508 | |||
509 | /** |
||
510 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
511 | * @covers OpCacheGUI\OpCache\Status::getCachedScripts |
||
512 | */ |
||
513 | public function testGetCachedScriptsZeroedTimestamp() |
||
536 | |||
537 | /** |
||
538 | * @covers OpCacheGUI\OpCache\Status::__construct |
||
539 | * @covers OpCacheGUI\OpCache\Status::getCachedScriptsForOverview |
||
540 | * @covers OpCacheGUI\OpCache\Status::getCachedScripts |
||
541 | * @covers OpCacheGUI\OpCache\Status::sortCachedScripts |
||
542 | */ |
||
543 | public function testGetCachedScriptsForOverviewFilled() |
||
600 | |||
601 | } |
||
602 |