File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 2222use function in_array ;
2323use function sort ;
2424
25+ use const SORT_FLAG_CASE ;
26+ use const SORT_NATURAL ;
27+
2528/** @implements IteratorAggregate<string> */
2629final 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> */
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments