Skip to content

Handbook: Modernize the plugin's PHPUnit test suite. - #747

Closed
obenland wants to merge 2 commits into
WordPress:trunkfrom
obenland:handbook/phpunit-suite
Closed

Handbook: Modernize the plugin's PHPUnit test suite.#747
obenland wants to merge 2 commits into
WordPress:trunkfrom
obenland:handbook/phpunit-suite

Conversation

@obenland

Copy link
Copy Markdown
Member

The handbook tests extended WP_UnitTestCase, whose set_up() calls PHPUnit\Util\Test::parseTestMethodAnnotations() — removed in PHPUnit 10. WordPress has no PHPUnit 10+ compatible test case, so every test errored before reaching an assertion.

They now extend a small local base test case that provides only the three helpers the suite actually uses (factory(), go_to(), assertQueryTrue()) plus the per-test isolation those depend on. Test bodies are unchanged.

Changes

  • Adds a wp-env test environment for the plugin, matching the ones the plugin and theme directories already use, and points the existing CI matrix entry at it. It previously had no config and relied on plugin auto-detection.
  • Renames the test files to match their class names, which PHPUnit now requires for directory-based discovery.
  • Replaces four assertions that hardcoded http://example.org/… with home_url(), so they no longer depend on the test suite's default domain.
  • Converts @dataProvider annotations to #[DataProvider] attributes, which PHPUnit 12 will require.
  • Varies the page navigation cache key by whether the current user can read private posts, so a cached page list is only reused for viewers it was built for, with tests covering both orderings.
  • Fixes a PHP 8.4 deprecation surfaced by the now-running suite: parse_url() returns null for a home URL with no path, which trim() no longer accepts.

Test-isolation fixes

Running the suite in randomized order surfaced two pre-existing order dependencies, both of which WP_UnitTestCase never guarded against either:

  • WPorg_Handbook_Admin_Notices_Test had no setUp(), so it only passed when it ran before any class whose tearDown() calls WPorg_Handbook_Init::reset().
  • test_filter_wporg_handbook_sidebar_args() overwrote the $wp_registered_sidebars global without restoring it.

Verification

140 tests, 227 assertions, no failures or deprecations on PHPUnit 11.5 / PHP 8.4, stable across repeated randomized ordering. Run locally with:

cd environments && npm run handbook:test

🤖 Generated with Claude Code

The tests extended WP_UnitTestCase, whose set_up() calls a PHPUnit API
that was removed in PHPUnit 10, so none of them could run on a current
PHPUnit. They now extend a small local base test case providing the few
WordPress helpers the suite actually uses.

Adds a wp-env test environment for the plugin, matching the ones the
plugin and theme directories already use, and points the existing CI
matrix entry at it. Test files are renamed to match their class names,
as PHPUnit now requires for directory-based discovery.

Also varies the page navigation cache key by whether the current user
can read private posts, so a cached list is only reused for viewers it
was built for, and adds coverage for it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 18:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props obenland.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Uses long array syntax, and wp_parse_url() in place of parse_url().

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bazza bazza closed this in 8b0c7ae Jul 29, 2026
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