Repository navigation
[6.x] Give plugin test suites Craft's facade aliases - #21204
Conversation
PluginTestCase disables package discovery, so plugin suites had none of Craft's facade aliases, and templates rendered in them had no facade Twig globals such as Sites. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1fc17-c592-763a-a600-e76afae5cd1f
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
📚 Storybook previews@craftcms/ui — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues requiring changes.
No open issues 🎉
What changed in this PR
This PR aligns plugin test suites with Craft’s own test setup by loading facade aliases explicitly, making globals such as Sites available in Twig without package discovery.
Changes:
- Load Craft’s facade aliases from
composer.jsoninPluginTestCase. - Preserve compatibility with untyped Testbench overrides and document parent-alias merging.
- Add a regression test for accessing the
Sitesfacade through Twig.
| File | Description |
|---|---|
tests/TestClasses/PluginTestSuite/tests/BootstrapTest.php |
Adds coverage for facade globals in plugin-rendered Twig. |
src/Plugin/Testing/PluginTestCase.php |
Registers Craft’s facade aliases during plugin test bootstrapping. |
Review effort: Balanced
Summary
PluginTestCaseboots Craft without package discovery, so plugin test suites got none of Craft's facade aliases. Templates rendered in a plugin's tests had no facade Twig globals:{{ Sites.getPrimarySite().handle }}This failed in a plugin suite while working on a site.
PluginTestCasenow loads the aliases from Craft'scomposer.json, as Craft's own test cases do.getPackageAliases()has no return type, so overrides written for Testbench's untyped method still load. Overrides should mergeparent::getPackageAliases($app).Evidence
tests/TestClasses/PluginTestSuite/tests/BootstrapTest.phpfails (PluginTestCaseTestruns that suite).After: it passes.
Related issues
CacheInfoTwig global needs it in plugin suites.