Skip to content

[6.x] Give plugin test suites Craft's facade aliases - #21204

Merged
riasvdv merged 1 commit into
6.xfrom
plugin-test-case-aliases
Nov 30, 2026
Merged

riasvdv merged 1 commit into
6.xfrom
plugin-test-case-aliases

Conversation

@timkelty

Copy link
Copy Markdown
Contributor

Summary

PluginTestCase boots 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. PluginTestCase now loads the aliases from Craft's composer.json, as Craft's own test cases do.

  • No changelog entry: plugin testing is new in 6.0.
  • getPackageAliases() has no return type, so overrides written for Testbench's untyped method still load. Overrides should merge parent::getPackageAliases($app).

Evidence

  • Before: the new test in tests/TestClasses/PluginTestSuite/tests/BootstrapTest.php fails (PluginTestCaseTest runs that suite).
    After: it passes.
it('exposes Craft facades as Twig globals', function () {
    expect(renderString('{{ Sites.getPrimarySite().handle }}'))->toBe(app(Sites::class)->getPrimarySite()->handle);
});

Related issues

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T22:06:31.463719Z ff80ab3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@linear-code

linear-code Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

CMS-2907

@github-actions

Copy link
Copy Markdown
Contributor

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.json in PluginTestCase.
  • Preserve compatibility with untyped Testbench overrides and document parent-alias merging.
  • Add a regression test for accessing the Sites facade 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

@riasvdv
riasvdv merged commit 422e655 into 6.x Nov 30, 2026
29 checks passed
@riasvdv
riasvdv deleted the plugin-test-case-aliases branch November 30, 2026 08:18
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.

3 participants