Skip to content

Commit d675c75

Browse files
committed
Standards/AbstractSniffUnitTest: order test files using natural sort
When a sniff has multiple test case files, the `AbstractSniffUnitTest::getTestFiles()` sorts the file names before passing them off to be run. While in most cases, the order of the test case files should not really matter, but in rare cases, like when testing that a property is being reset correctly between files, it does. As things were, the `sort()` function without flags was being used, making the file order unnatural to work with ( file `11` would be run before file `2` - see: https://3v4l.org/VPO3Z ). As the `SORT_NATURAL` flag is available since PHP 5.4, adding that flag will resolve this and will ensure the test case files are run in their natural order. Optionally, the flag could be combined with the `SORT_FLAG_CASE` flag to make the sort case-insensitive.
1 parent 11d5c66 commit d675c75

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ The file documents changes to the PHP_CodeSniffer project.
8585
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
8686
- The -e (explain) command will now list sniffs in natural order
8787
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
88+
- Tests using the PHPCS native test framework with multiple test case files will now run the test case files in numeric order.
89+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
8890

8991
### Removed
9092
- Removed support for installing via PEAR

tests/Standards/AbstractSniffUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function getTestFiles($testFileBase)
9090
}
9191

9292
// Put them in order.
93-
sort($testFiles);
93+
sort($testFiles, SORT_NATURAL);
9494

9595
return $testFiles;
9696

0 commit comments

Comments
 (0)