Skip to content

feat(phpunit): support extra_themes theme dependencies in phpunit recipes - #2605

Draft
chubes4 wants to merge 1 commit into
mainfrom
fix/issue-2604-wp-codebox
Draft

chubes4 wants to merge 1 commit into
mainfrom
fix/issue-2604-wp-codebox

Conversation

@chubes4

@chubes4 chubes4 commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

wordpress.phpunit recipes can now declare theme dependencies. recipe build phpunit and buildWordPressPhpunitRecipe accept extra_themes and write them into the recipe as inputs.extra_themes plus a dependency-themes-json step arg. The existing generic recipe path mounts those themes. The managed PHPUnit bootstrap now makes the activate: true theme the active theme for the test site and loads its functions.php before fixtures and tests. If a theme is passed in extra_plugins by mistake, validation now says it looks like a theme and points to extra_themes. Both new test files pass locally. The integration test boots Playground and a component PHPUnit test that calls a theme helper passes (1 test, 4 assertions).

What changed

  • packages/cli/src/commands/recipe-build.ts: the phpunit builder options accept extra_themes and pass them to buildWordPressPhpunitRecipe.
  • packages/runtime-core/src/recipe-builders.ts: extra_themes is checked (needs a source, at most one active theme, unique slugs), emitted as inputs.extra_themes, and turned into the dependency-themes-json arg. New exported helper phpunitDependencyThemes. Slugs are resolved the same way the CLI does it (mountSlug, then slug, then the local source folder name).
  • packages/runtime-playground/src/phpunit-command-handlers.ts and wordpress-command-runners.ts: dependency-themes-json is parsed by the new parsePhpunitDependencyThemes. A new load_theme_deps stage runs after dependency plugins and their plugins_loaded callbacks, before init is replayed. It checks the themes are mounted under wp-content/themes, sets the template/stylesheet options (child plus parent), loads functions.php (child first, then parent, matching WordPress) and runs any new after_setup_theme callbacks. This stage is needed because the wp-phpunit install runs with WP_INSTALLING set, so WordPress never loads theme functions during the managed bootstrap.
  • packages/cli/src/recipe-validation.ts: when an extra_plugins source has no plugin entry file but has a style.css with Theme Name:, the missing-path ...pluginFile issue now says the source looks like a theme and to use extra_themes. The message for an ordinary missing file is unchanged.
  • tests/phpunit-extra-themes.test.ts (new): covers what the CLI builder emits, the builder's error checks, the new and unchanged validation messages, parsing of the runner arg, stage ordering and a php -l check of the generated bootstrap. It also runs the generated theme stage in host PHP against real child and parent theme folders with minimal WordPress stubs, and checks that a missing mount fails clearly.
  • tests/phpunit-extra-themes.integration.test.ts (new): runs a full Playground recipe-run in which a plugin's WP_UnitTestCase calls a theme helper, checks get_stylesheet() and checks that after_setup_theme fired. It is added to the serial list in scripts/smoke-discovery.ts.
  • docs/recipe-contract.md: documents the phpunit builder's extra_themes option and the bootstrap behaviour.

Verification

  • 1-verify-file-18b8693431fb61faaaf9c0d6c4e8e95fabc519f81dac821f749784e80b59643b.txt (npm run build && npx tsx tests/phpunit-extra-themes.test.ts): passed on 3f3632f. Base main@85ccba4 unchanged. 6694 ms; retained gate metadata.

  • HOMEBOY_LINT_BASE=85ccba40b5b36873c79468bb65affea45ce1a975 homeboy --placement l (HOMEBOY_LINT_BASE=85ccba40b5b36873c79468bb65affea45ce1a975 homeboy --placement local review lint wp-codebox --path . --…): passed on 3f3632f. Base main@85ccba4 unchanged. 72095 ms; retained gate metadata.

  • repro: none (no repro gate was declared, so these gates do not prove the issue).

  • CI: pending

Cook run
  • Cook ID: agent-task-78ab7652-90fa-4e78-acab-af0506fbbfa8
  • Attempt run ID: agent-task-78ab7652-90fa-4e78-acab-af0506fbbfa8-attempt-1-445c6791
  • Gate 1: tree 0fa6f1801f25ea2b5bbbfe356f52a2e665525f8a
  • Gate 2: tree 0fa6f1801f25ea2b5bbbfe356f52a2e665525f8a

Delivery

  • Delivered: recipe build phpunit accepts extra_themes and emits it into the recipe
  • Delivered: theme dependency functions.php is callable from component PHPUnit tests under the managed bootstrap
  • Delivered: validation message for theme-shaped extra_plugins points to extra_themes
  • Delivered: tests/phpunit-extra-themes.test.ts plus a Playground integration test

Evidence

  • npx tsx tests/phpunit-extra-themes.integration.test.ts boots Playground with the theme declared through extra_themes. The plugin's test calls consumer_theme_helper(), checks get_stylesheet() === 'consumer-theme' and checks that after_setup_theme fired. PHPUnit reports 'OK (1 test, 4 assertions)'.

AI disclosure

Tool: Homeboy Cook. Agent: Homeboy (roadie). Model: roadie · route cook-heavy · served claude-opus-5-5. Cook time: 25m47s.

Implementation and reviewer documentation were written by the AI, under the direction of the Cook requester. Gates were run by Homeboy. A human reviews before merge.

Refs #2604

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.

1 participant