Skip to content

Commit 2802f1f

Browse files
authored
Merge pull request #1215 from phpDocumentor/fix/order-files
Fix natural case insensitive sort for files
2 parents 8330dec + 3128936 commit 2802f1f

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

packages/guides/src/Files.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
use function in_array;
2323
use function sort;
2424

25+
use const SORT_FLAG_CASE;
26+
use const SORT_NATURAL;
27+
2528
/** @implements IteratorAggregate<string> */
2629
final class Files implements IteratorAggregate, Countable
2730
{
@@ -35,7 +38,7 @@ public function add(string $filename): void
3538
}
3639

3740
$this->files[] = $filename;
38-
sort($this->files);
41+
sort($this->files, SORT_NATURAL | SORT_FLAG_CASE);
3942
}
4043

4144
/** @return Iterator<string> */
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides;
15+
16+
use PHPUnit\Framework\TestCase;
17+
18+
use function iterator_to_array;
19+
20+
class FilesTest extends TestCase
21+
{
22+
public function testFilesAreSorted(): void
23+
{
24+
$files = new Files();
25+
$files->add('page');
26+
$files->add('Subpage');
27+
$files->add('index');
28+
29+
$result = iterator_to_array($files->getIterator());
30+
31+
self::assertSame(
32+
[
33+
'index',
34+
'page',
35+
'Subpage',
36+
],
37+
$result,
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)