Skip to content

Standards/AbstractSniffUnitTest: order test files using natural sort#55

Merged
jrfnl merged 1 commit into
masterfrom
feature/test-file-sorting
Dec 4, 2023
Merged

Standards/AbstractSniffUnitTest: order test files using natural sort#55
jrfnl merged 1 commit into
masterfrom
feature/test-file-sorting

Conversation

@jrfnl

@jrfnl jrfnl commented Nov 9, 2023

Copy link
Copy Markdown
Member

Description

Recreation of upstream PR squizlabs/PHP_CodeSniffer#3775:

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.

Suggested changelog entry

Tests using the PHPCS native test framework with multiple test case files will now run the test case files in numeric order.

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.
@jrfnl jrfnl force-pushed the feature/test-file-sorting branch from 2cdfca7 to d675c75 Compare December 4, 2023 14:46
@jrfnl jrfnl merged commit 45d33e0 into master Dec 4, 2023
@jrfnl jrfnl deleted the feature/test-file-sorting branch December 4, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant