[Testing] Use fresh single-file source locator under PHPUnit to avoid stale reflection - #8464
Merged
Merged
Conversation
… stale reflection Fixture files are written to throwaway temp paths and deleted in tearDown. The shared OptimizedSingleFileSourceLocatorRepository caches locators by path for the whole worker and never evicts them, so a stale locator for a since-deleted file can leak into a later test running in the same parallel worker. Depending on how fastunit groups tests into worker chunks, this surfaces as an order-dependent reflection failure (e.g. a parent property becoming invisible), reproducible with a low worker count such as -p 4. Build a fresh locator per run under PHPUnit; keep the cached repository in production where files are stable.
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.
Problem
Rule tests write each fixture to a throwaway temp file and delete it in
tearDown(). The sharedOptimizedSingleFileSourceLocatorRepositorycaches single-file locators by path for the whole worker and never evicts them. So a stale locator for a since-deleted fixture file can leak into a later test that runs in the same parallel worker.Because
fastunitgroups tests into worker chunks by weight, whether this bites depends on how the chunks fall out - adding or removing test classes reshuffles the grouping. That makes it an intermittent, order-dependent failure: a test can go red not from its own change but from what it happens to share a worker with.It reproduces reliably at a low worker count (matching CI's core count):
The symptom is a rule that resolves reflection (e.g. a parent property) suddenly seeing incomplete data - the parent property becomes invisible and the expected change is not applied - accompanied by
hash_file(... /Fixture/fixture.php): Failed to open stream: No such filewarnings from the stale locator.Fix
Under PHPUnit, build a fresh single-file locator via
OptimizedSingleFileSourceLocatorFactory::create()instead of the cachedgetOrCreate(). Production keeps the cached repository, where files are stable and caching is a performance win. TheisPHPUnitRunguard already exists inprovide()for the aggregate locator; this extends the same reasoning to the single-file locators.Validation
Full suite green across worker counts that previously failed:
vendor/bin/fastunit -p 4 …-> OKvendor/bin/fastunit -p 3 …-> OKcomposer check-cs,composer phpstan, andcomposer rectorpass on the changed file.