diff --git a/src/IterableCodeExtractor.php b/src/IterableCodeExtractor.php index a0e9b148..7edc3f6a 100644 --- a/src/IterableCodeExtractor.php +++ b/src/IterableCodeExtractor.php @@ -234,6 +234,8 @@ function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions ) { $filtered_files[] = Utils\normalize_path( $file->getPathname() ); } + sort( $filtered_files, SORT_NATURAL | SORT_FLAG_CASE ); + return $filtered_files; } } diff --git a/tests/IterableCodeExtractorTest.php b/tests/IterableCodeExtractorTest.php index bdca27f3..d5d29e76 100644 --- a/tests/IterableCodeExtractorTest.php +++ b/tests/IterableCodeExtractorTest.php @@ -110,4 +110,17 @@ public function test_can_override_exclude_by_include() { $expected = static::$base . 'foo/bar/excluded/ignored.js'; $this->assertContains( $expected, $result ); } + + public function test_can_return_all_directory_files_sorted() { + $result = IterableCodeExtractor::getFilesFromDirectory( self::$base, [ '*' ], [], [ 'php', 'js' ] ); + $expected = array( + static::$base . 'baz/includes/should_be_included.js', + static::$base . 'foo-plugin/foo-plugin.php', + static::$base . 'foo/bar/excluded/ignored.js', + static::$base . 'foo/bar/foo/bar/foo/bar/deep_directory_also_included.php', + static::$base . 'foo/bar/foofoo/included.js', + static::$base . 'hoge/should_NOT_be_included.js', + ); + $this->assertEquals( $expected, $result ); + } }