Skip to content

Commit 6544911

Browse files
committed
Fixed sorting of cached scripts
1 parent 25a6495 commit 6544911

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/OpCacheGUI/OpCache/Status.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ public function getCachedScripts()
260260
];
261261
}
262262

263+
usort($scripts, [$this, 'sortCachedScripts']);
264+
263265
return $scripts;
264266
}
267+
268+
/**
269+
* Sorts the lists of cached scripts
270+
*
271+
* @param array $a Array to compare
272+
* @param array $b Array to compare
273+
*
274+
* @return int The direction of the sort
275+
*/
276+
private function sortCachedScripts(array $a, array $b)
277+
{
278+
return strcmp($a['full_path'], $b['full_path']);
279+
}
265280
}

test/Unit/OpCache/StatusTest.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ public function testGetCachedScriptsEmpty()
319319
/**
320320
* @covers OpCacheGUI\OpCache\Status::__construct
321321
* @covers OpCacheGUI\OpCache\Status::getCachedScripts
322+
* @covers OpCacheGUI\OpCache\Status::sortCachedScripts
322323
*/
323324
public function testGetCachedScriptsFilled()
324325
{
@@ -328,6 +329,13 @@ public function testGetCachedScriptsFilled()
328329
$status = new Status($formatter, $this->statusData);
329330

330331
$data = [
332+
[
333+
'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php',
334+
'hits' => 12876,
335+
'memory_consumption' => '6KB',
336+
'last_used_timestamp' => '14:25:15 09-10-2014',
337+
'timestamp' => 'N/A',
338+
],
331339
[
332340
'full_path' => '/var/www/vhosts/OpcacheGUI/src/OpCacheGUI/Network/Request.php',
333341
'hits' => 1,
@@ -342,34 +350,27 @@ public function testGetCachedScriptsFilled()
342350
'last_used_timestamp' => '14:08:35 09-10-2014',
343351
'timestamp' => '16:20:53 07-10-2014',
344352
],
345-
[
346-
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php',
347-
'hits' => 19,
348-
'memory_consumption' => '3KB',
349-
'last_used_timestamp' => '15:31:55 09-10-2014',
350-
'timestamp' => '20:07:33 08-10-2014',
351-
],
352353
[
353354
'full_path' => '/var/www/vhosts/RedTube/template/humiliation/germany-vs-brazil.phtml',
354355
'hits' => 71,
355356
'memory_consumption' => '4KB',
356357
'last_used_timestamp' => '14:25:15 09-10-2014',
357358
'timestamp' => '20:01:15 08-10-2014',
358359
],
360+
[
361+
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Foo.php',
362+
'hits' => 19,
363+
'memory_consumption' => '3KB',
364+
'last_used_timestamp' => '15:31:55 09-10-2014',
365+
'timestamp' => '20:07:33 08-10-2014',
366+
],
359367
[
360368
'full_path' => '/var/www/vhosts/SomeOtherProject/src/Psr/Autoloader.php',
361369
'hits' => 32,
362370
'memory_consumption' => '5KB',
363371
'last_used_timestamp' => '14:25:15 09-10-2014',
364372
'timestamp' => '20:01:15 08-10-2014',
365373
],
366-
[
367-
'full_path' => '/var/www/vhosts/NoTimeStamp/src/Psr/Autoloader.php',
368-
'hits' => 12876,
369-
'memory_consumption' => '6KB',
370-
'last_used_timestamp' => '14:25:15 09-10-2014',
371-
'timestamp' => 'N/A',
372-
],
373374
];
374375

375376
$this->assertSame($data, $status->getCachedScripts());

0 commit comments

Comments
 (0)