Skip to content

test: isolate WordPress hooks between feature tests - #330

Merged
ogorzalka merged 1 commit into
mainfrom
feat/isolate-wp-hooks-in-tests
Dec 4, 2026
Merged

ogorzalka merged 1 commit into
mainfrom
feat/isolate-wp-hooks-in-tests

Conversation

@ogorzalka

@ogorzalka ogorzalka commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

What this changes

New projects use Pollora\Testing\IsolatesWordPressHooks (pollora/framework v13.45.2) in tests/TestCase.php, so the WordPress hooks of one feature test no longer reach the next one. This is the skeleton side of Pollora/framework#741.

  • composer.json requires pollora/framework ^13.45.2. The lock already pinned v13.45.2; only its content-hash changes.
  • tests/Feature/WordPressHookIsolationTest.php ships with every project. It is one test that builds its applications itself (tearDown() then setUp()), so it does not depend on order or on other tests being selected. It checks that hooks added by the test (add_action() and the Action facade) are gone in the next application, that wp_footer runs in a later application, that the number of callbacks is the same in two successive applications, and that the views of a theme found in themes/ are registered in later applications.
  • phpunit.xml is unchanged and keeps APP_ENV=testing, which the test also asserts.

How to test it

ddev exec php artisan test tests/Feature/WordPressHookIsolationTest.php

Only the Install (locked) and Install (develop) jobs of tests.yml run tests/Feature (ddev composer test, on an installed WordPress with the default theme). The install scenarios, assets, content and the harness jobs do not run it.

With and without the trait, on an installed WordPress, in both Install jobs (locked and develop) of https://github.com/Pollora/pollora/actions/runs/47373396266. That run was started by hand on a temporary branch, since deleted: this commit without the use IsolatesWordPressHooks; line, plus a temporary file holding the wp_footer and callback-count cases separately, and a step printing the Pest output. Its two commits on top of this one: c4feb36b (trait removed) and 6ace2a12 (temporary cases and workflow step). The jobs are green because the failing commands were tolerated there; the results are in the log.

Command Without the trait With the trait
new test alone fails: Failed asserting that true is false (the probe hook is still there) 1 passed, 8 assertions
wp_footer case alone fails: Target [Pollora\Theme\Domain\Contracts\ThemeJsonResolverInterface] is not instantiable. passed
callback count case alone fails: 1365 is identical to 1215 passed
whole suite 3 failed (the new test and the two temporary cases), 23 passed 26 passed

Lock is current is skipped on pull requests from a branch with this name, so it was started by hand on this branch: https://github.com/Pollora/pollora/actions/runs/47372445631

What this does not prove

  • No run on a local WordPress: the evidence is the CI runs above.
  • The shipped test stops at its first failing assertion; wp_footer and the callback count were shown failing on their own through the temporary copies only.
  • The theme assertion is a guard against regressions: the framework registers the theme again with or without the trait. It asserts nothing in a project without themes/<active theme>/resources/views.
  • wp_footer also runs the callbacks of the project it ships to; only the stock skeleton and default theme are covered by CI.
  • RefreshDatabase, parallel testing, multisite and third-party plugins are not covered.
  • A hook added by a file first included during a test is removed with that test (a limit of the trait).

Checklist

  • Targets main (this repository has no develop branch)
  • ddev composer test passes: in CI, in both Install jobs of this pull request (not run locally)
  • Pint run on the changed PHP files (Pint 1.32.1 on the host, with this repository's pint.json)
  • If it touches the install path: not applicable
  • CHANGELOG.md updated under [Unreleased]

Also run locally: .github/scripts/check-skeleton-content.sh, .github/scripts/tests/check-upstream.test.sh, .github/scripts/check-upstream.sh and composer validate. The skeleton defines no composer qa:fast or composer qa script.

Tests\TestCase uses Pollora\Testing\IsolatesWordPressHooks, and a feature
test guards it. Requires pollora/framework ^13.45.2.

Refs Pollora/framework#741
@ogorzalka
ogorzalka merged commit 3d8b5e0 into main Dec 4, 2026
22 checks passed
@ogorzalka
ogorzalka deleted the feat/isolate-wp-hooks-in-tests branch December 4, 2026 16:19
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