Handbook: Modernize the plugin's PHPUnit test suite. - #747
Closed
obenland wants to merge 2 commits into
Closed
Conversation
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>
|
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 Core Committers: Use this line as a base for the props when committing in SVN: 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The handbook tests extended
WP_UnitTestCase, whoseset_up()callsPHPUnit\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
http://example.org/…withhome_url(), so they no longer depend on the test suite's default domain.@dataProviderannotations to#[DataProvider]attributes, which PHPUnit 12 will require.parse_url()returnsnullfor a home URL with no path, whichtrim()no longer accepts.Test-isolation fixes
Running the suite in randomized order surfaced two pre-existing order dependencies, both of which
WP_UnitTestCasenever guarded against either:WPorg_Handbook_Admin_Notices_Testhad nosetUp(), so it only passed when it ran before any class whosetearDown()callsWPorg_Handbook_Init::reset().test_filter_wporg_handbook_sidebar_args()overwrote the$wp_registered_sidebarsglobal 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:
🤖 Generated with Claude Code