Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow sorting tests newest first#6551

Draft
tgolsen wants to merge 2 commits into
sebastianbergmann:mainsebastianbergmann/phpunit:mainfrom
tgolsen:feature/sort-by-test-agetgolsen/phpunit:feature/sort-by-test-ageCopy head branch name to clipboard
Draft

Allow sorting tests newest first#6551
tgolsen wants to merge 2 commits into
sebastianbergmann:mainsebastianbergmann/phpunit:mainfrom
tgolsen:feature/sort-by-test-agetgolsen/phpunit:feature/sort-by-test-ageCopy head branch name to clipboard

Conversation

@tgolsen

@tgolsen tgolsen commented Mar 25, 2026

Copy link
Copy Markdown

This is my first contribution to PHPUnit. I tried to follow convention best as I could including copying the copyright notice on the fixture test classes. Hope that's right.

This PR introduces a --order-by newest option for chronological test sorting, running the most recently modified test files first.

When developing tests in a project with a lot of existing tests, I wanted my new ones to go first. This new execution order option prioritizes recently modified test files. Combined with --stop-on-failure it can save time for a developer manually running tests.

Changes

  • New execution order constant: TestSuiteSorter::ORDER_NEWEST
  • CLI option: --order-by newest
  • Sorting logic: Tests are ordered by file modified time

Design Decisions

  • Implements newest-first ordering only, as oldest-first has no obvious (to me) use case
  • Sorts at the test class file level rather than individual test methods (by necessity)
  • Test suites are sorted by the modification time of the first test in the suite, I thought this was a reasonable answer for what to do with suites rather than a more complex check of the content

Testing

  • Added end-to-end test with fixture files
  • Test includes setup script to maintain consistent file timestamps

Usage

# Run tests with newest files first
phpunit --order-by newest

@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/test-runner CLI test runner labels Mar 26, 2026
@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.06%. Comparing base (2dd2490) to head (f5a508e).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #6551   +/-   ##
=========================================
  Coverage     96.06%   96.06%           
- Complexity     7569     7581   +12     
=========================================
  Files           817      817           
  Lines         23415    23447   +32     
=========================================
+ Hits          22493    22525   +32     
  Misses          922      922           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebastianbergmann

Copy link
Copy Markdown
Owner

Thank you for your contribution. Sorry that my recent work on the main branch has led to merge conflicts that I need to ask you to resolve.

@tgolsen

tgolsen commented Apr 17, 2026

Copy link
Copy Markdown
Author

Thanks for your reply. I will resolve the conflicts and submit again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature/test-runner CLI test runner type/enhancement A new idea that should be implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.