Build/Test Tools: Preserve plugin query vars between tests - #12730
Build/Test Tools: Preserve plugin query vars between tests#12730ArkaPrabhaChowdhury wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Preserves plugin-registered public query vars across PHPUnit test teardown when running the WordPress test suite in non-core (“plugin”) mode, preventing rewrite endpoints registered during bootstrap/init from disappearing after the first test.
Changes:
- Capture the initial
$wp->public_query_varsduring bootstrap for non-core test runs. - Restore those captured query vars onto the fresh
WPinstance created duringWP_UnitTestCase::tear_down(). - Add regression tests that validate preservation across an actual test teardown boundary.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/phpunit/includes/bootstrap.php | Captures initial public query vars after wp-settings.php in non-core mode. |
| tests/phpunit/includes/abstract-testcase.php | Restores captured public query vars during test teardown when present. |
| tests/phpunit/tests/rewrite/addRewriteEndpoint.php | Adds regression coverage validating query vars persist across teardown in plugin-mode scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function test_should_preserve_query_vars_registered_during_plugin_bootstrap() { | ||
| add_rewrite_endpoint( 'plugin-endpoint', EP_ROOT ); | ||
| $GLOBALS['_wp_tests_initial_public_query_vars'] = $GLOBALS['wp']->public_query_vars; | ||
|
|
||
| $this->assertContains( 'plugin-endpoint', $GLOBALS['wp']->public_query_vars ); | ||
| } | ||
|
|
||
| /** | ||
| * Verifies the query variables after the preceding test's tear down. | ||
| * | ||
| * @ticket 37207 | ||
| * | ||
| * @depends test_should_preserve_query_vars_registered_during_plugin_bootstrap | ||
| */ | ||
| public function test_should_restore_query_vars_registered_during_plugin_bootstrap() { | ||
| try { | ||
| $this->assertContains( 'plugin-endpoint', $GLOBALS['wp']->public_query_vars ); | ||
| } finally { | ||
| unset( $GLOBALS['_wp_tests_initial_public_query_vars'] ); | ||
| } | ||
| } |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Preserves public query variables registered by plugins during bootstrap when the WordPress test suite runs in non-core mode. This prevents endpoints registered on init from disappearing after the first test while retaining the existing reset behavior for core tests.
Adds regression coverage across the actual test teardown boundary.
Trac ticket: https://core.trac.wordpress.org/ticket/37207
Testing
Use of AI Tools
AI assistance: Yes
Tool(s): OpenAI Codex
Model(s): GPT-5
Used for: Ticket investigation, implementation, regression tests, and local validation; the resulting diff and test output were reviewed before publication.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.