Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix test state issues around sites cache #11455

Merged
merged 2 commits into from
Feb 14, 2025
Merged

Conversation

jesseleite
Copy link
Member

@jesseleite jesseleite commented Feb 14, 2025

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...

rm -rf vendor
composer update
phpunit --filter SubstitutesEntryForLivePreviewTest

CleanShot 2025-02-14 at 10 29 25

...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 our TestCase 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...

$site = $site ?? $this->stache->sites()->first();

Which uses a separate sites cache here...

$stache->sites(Site::all()->keys()->all());

Which we think should just be a Site::default() call, using the Sites 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 👌

@jasonvarga jasonvarga merged commit 8439c2c into 5.x Feb 14, 2025
19 checks passed
@jasonvarga jasonvarga deleted the fix-testing-state-issues branch February 14, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants