[5.x] Fix test state issues around sites cache #11455
Merged
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.
The problem
We were intermittently seeing test errors related to sites, but only when running certain tests with no cache state. For example, this would fail...
...but only on the first run. That test would pass on subsequent runs, or when running the whole suite, because sites state had been built up already.
The solution
The way our
Sites
class works, it caches$sites
as a property cache, and has some fallback logic as well. We intentionally set up a default sites.yaml in ourTestCase
class, so we should just be making sure that file gets set up early enough for when the facade runs.Note
We also have a bit more work to do around places like this...
cms/src/Stache/Repositories/EntryRepository.php
Line 75 in 297ed95
Which uses a separate sites cache here...
cms/src/Stache/ServiceProvider.php
Line 45 in 297ed95
Which we think should just be a
Site::default()
call, using theSites
class property cache as a single source of truth, as we do everywhere else in Statamic. Jason has a PR incoming to make this change for v6 👌