Cache which tests a test file contains - #6863
Draft
sebastianbergmann wants to merge 29 commits into
Draft
Conversation
API Surface ChangesIf any of the additions below are not intended as public API, mark them with New API SurfaceMethods
Modified API SurfaceMethods
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6863 +/- ##
============================================
- Coverage 99.48% 99.47% -0.02%
- Complexity 9416 9596 +180
============================================
Files 915 922 +7
Lines 28736 29126 +390
============================================
+ Hits 28589 28974 +385
- Misses 147 152 +5 ☔ View full report in Codecov by Harness. |
Contributor
|
to make the user aware of the opt-in performance feature it might be worth sending a warning/notice/whatever when (maybe such thing is already implemented, but the PR is very huge, so I was not able to read thru all of it) |
sebastianbergmann
force-pushed
the
feature/test-index
branch
2 times, most recently
from
August 1, 2026 06:58
3a3c30e to
b77fa0c
Compare
sebastianbergmann
force-pushed
the
feature/test-index
branch
from
August 6, 2026 15:14
b77fa0c to
57678ac
Compare
…-extension in one place
sebastianbergmann
force-pushed
the
feature/test-index
branch
from
August 9, 2026 01:46
57678ac to
21a5578
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running a subset of a large test suite is slower than it should be. Before PHPUnit can decide that a test file has nothing to contribute to the run, it has to load that file, and loading a test file is most of the work. On a suite of a few hundred files,
--group something-narrowspends nearly all of its time loading files whose tests are then filtered away again.This pull request adds an opt-in cache that remembers which tests each test file contains and which groups they are in, so that on a later run PHPUnit can decide not to load a file at all.
Using it
The cache is off by default. Turn it on in the XML configuration file:
or on the command line:
It needs a cache directory, the same one the test run history and the static analysis cache for code coverage use. When the option is enabled without one, PHPUnit says so instead of quietly doing nothing.
What it does for you
Measured on PHPUnit's own
unittest suite (524 test files), comparing a run with a warm cache against the same run without the cache:--group test-runner/test-index(98 tests)--group framework/assertions(1481 tests)--filter TestIndexTest(42 tests)The narrower the selection, the more there is to save. The gain is in test discovery, so it is a fixed saving per run rather than a percentage. This makes it most noticeable exactly where it is most annoying, on the quick focused runs you do dozens of times an hour.
Building the cache on the very first run is not free, but that cost is repaid in full by the second run.
What it does not change
The tests that run
A file is only skipped when the cache can prove that nothing in it could have been selected anyway. Selecting tests by group and selecting them by name are each sufficient on their own to establish that, and both are consulted. Every measurement above was checked to select exactly the same tests, in the same order, as the same command without the cache.
What PHPUnit tells you
If loading a file makes PHPUnit warn about that file, the file is never skipped, so the same command keeps producing the same output. Otherwise a warning would appear on the first run and silently vanish on the second.
Anything, when it is off
The cache is opt-in and defaults to off.
Staying correct as you work
An entry is used only while every source file it was derived from still has the contents it had when the entry was written. That includes parent classes and traits, so adding a test to an abstract base class or changing a group on a trait is noticed in every test class that inherits from it.
Files that could not be loaded are never remembered, so a run that fails will fail the same way again rather than being skipped past.