Repository navigation
Tests: Reset scripts and styles after each Test_WP_Customize_Nav_Menus test - #16159
noruzzamans wants to merge 1 commit into
Conversation
…s test Test_WP_Customize_Nav_Menus::test_customize_preview_enqueue_deps() calls WP_Customize_Nav_Menus::customize_preview_enqueue_deps(), which enqueues the customize-preview-nav-menus script and its dependencies. Test setup also instantiates WP_Customize_Manager into $GLOBALS['wp_customize']. Adding tear_down() ensures $this->wp_customize, $GLOBALS['wp_customize'], $GLOBALS['wp_scripts'], and $GLOBALS['wp_styles'] are cleanly reset between tests, preventing leaked global state across test runs. Props noruzzamanrubel. See #66755.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the per-test Customizer and asset-state cleanup.
No open issues 🎉
What changed in this PR
Improves test isolation for Test_WP_Customize_Nav_Menus by clearing Customizer and asset state after each test, following the cleanup pattern used by related Customizer tests.
Changes:
- Adds
tear_down()to clear the instance’s Customizer reference and unset thewp_customize,wp_scripts, andwp_stylesglobals. - Calls the parent teardown after cleanup.
| File | Description |
|---|---|
tests/phpunit/tests/customize/nav-menus.php |
Adds per-test cleanup to prevent shared global state from leaking into subsequent tests. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
Could you show a pair of existing tests that fails on trunk in a fixed order and passes with the smallest reset? The nav-menu preview method enqueues customize-preview-nav-menus. Its dependencies are registered, but they aren’t added individually to WP_Dependencies::$queue. That distinction matters for the selective-refresh test, which inspects the queue directly.
Please narrow the teardown to the state that the failing test reads. This class already clears $wp_customize at the start of each test through clean_up_global_scope(). If an existing class fixture sees it before that reset, please name it and include it in the reproduction. The results currently listed in the PR all pass with the patch and don’t establish which of the four resets is necessary.
AI review · gpt-6
|
Thank you for the detailed inspection and explanation, @lancewillett. You are completely right—since Closing this PR so ticket #66755 stays strictly focused on reproducible isolation failures. |
Test_WP_Customize_Nav_Menus::test_customize_preview_enqueue_deps()callsWP_Customize_Nav_Menus::customize_preview_enqueue_deps(), which enqueues thecustomize-preview-nav-menusscript and its dependencies (jquery,wp-util,customize-preview,customize-selective-refresh). In addition, test setup instantiatesWP_Customize_Managerinto$GLOBALS['wp_customize'].Previously,
Test_WP_Customize_Nav_Menusdid not implementtear_down(), leaving$wp_customize,$wp_scripts, and$wp_stylespopulated in the global scope across tests.Trac ticket: https://core.trac.wordpress.org/ticket/66755
What changes
tear_down()inTest_WP_Customize_Nav_Menusto reset$this->wp_customize = null;,unset( $GLOBALS['wp_customize'] );,unset( $GLOBALS['wp_scripts'] );, andunset( $GLOBALS['wp_styles'] );before callingparent::tear_down(), matching the isolation pattern used inTests_WP_Customize_WidgetsandTests_WP_Customize_Manager.Testing
Locally tested with Docker (PHP 8.4, MySQL 9.7, PHPUnit 9.6.39):
npm run test:php -- --filter Test_WP_Customize_Nav_Menus: OK (29 tests, 196 assertions).npm run test:php -- --group customize: OK (243 tests, 2,258 assertions).npm run test:php -- --group customize --order-by=random --random-order-seed=42: OK (243 tests, 2,254 assertions).npm run test:php -- -c tests/phpunit/multisite.xml --group customize: OK (244 tests, 2,264 assertions)../vendor/bin/phpcs tests/phpunit/tests/customize/nav-menus.php: 0 errors, 0 warnings.