Skip to content

Tests: Prevent state leaks in functions tests - #13182

Closed
sirreal wants to merge 9 commits into
WordPress:trunkfrom
sirreal:agent/test-order-functions-isolation
Closed

sirreal wants to merge 9 commits into
WordPress:trunkfrom
sirreal:agent/test-order-functions-isolation

Conversation

@sirreal

@sirreal sirreal commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Resets the forced-SSL function-static fixture and resynchronizes timezone-choice translation state after locale-changing data sets.
  • Keeps the changes confined to PHPUnit tests and fixtures.

Verification

  • 100 randomized functions-group runs passed; each completed 1,212 tests and 2,499 assertions with 27 known warnings and one skip.
  • The continuation covered seeds 1789042001 through 1789042050; authoritative PHPUnit times remained below 50 seconds.
  • Replayed the original failing seed and focused contaminator/consumer cases during diagnosis.
  • PHP syntax checks passed for every changed PHP file.
  • git diff --check passed.

Trac: https://core.trac.wordpress.org/ticket/65893

@lancewillett

lancewillett commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Updated this branch with current trunk and fixed the PHPCS assignment-alignment warning in wpTimezoneChoice.php.

Validation: targeted PHPCS passes. The focused PHPUnit file could not run because the local test configuration file is not present.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@sirreal
sirreal force-pushed the agent/test-order-functions-isolation branch from 579de47 to d46ce5d Compare September 9, 2026 12:16
@sirreal
sirreal marked this pull request as ready for review September 9, 2026 12:16
@github-actions

github-actions Bot commented Sep 9, 2026 •

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 jonsurrell, lancewillett, mindctrl.

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

Comment thread tests/phpunit/tests/functions/wpTimezoneChoice.php Outdated

@sirreal sirreal left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not happy with this approach as it is now. The cleanup should cleanup, and tests shouldn't need to set a flag to trigger cleanup behavior.

@sirreal
sirreal marked this pull request as draft September 10, 2026 11:37
Drop the `$restore_timezone_translations` property. `tear_down()` now
resynchronizes `wp_timezone_choice()`'s locale static after every test,
so no test has to opt in to its own cleanup. The resync runs before
`parent::tear_down()`, which restores the hook snapshot and so undoes
the `load_textdomain` and `gettext` calls the resync fires.

In `Tests_Functions_ForceSslAdmin`, capture the `force_ssl_admin()`
value in `set_up()` and restore it in `tear_down()` instead of writing a
hard-coded `false`, following `tests/phpunit/tests/url.php`.
@mindctrl

Copy link
Copy Markdown
Member

@sirreal this seems to be working well now. I ran all the individual tests isolated in both classes, together in both, and the functions group. Anything else you want to do here?

Comment thread tests/phpunit/tests/functions/wpTimezoneChoice.php Outdated
@sirreal
sirreal marked this pull request as ready for review September 16, 2026 09:23
@sirreal

sirreal commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

I've cleaned up some changes I wasn't happy with and now I'm satisfied. Ready for review and merge. @mindctrl I did change some things since your testing if you'd care to re-run. Thanks for the feedback so far!

wporg-sync pushed a commit that referenced this pull request Sep 16, 2026
Reset forced admin SSL to its configured startup value after each test. Resynchronize timezone translations with the restored locale after each timezone-choice test, preventing function-static state from leaking between tests.

Developed in: #13182

Props jonsurrell, mindctrl.
See #65893.


git-svn-id: https://develop.svn.wordpress.org/trunk@63640 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Sep 16, 2026
Reset forced admin SSL to its configured startup value after each test. Resynchronize timezone translations with the restored locale after each timezone-choice test, preventing function-static state from leaking between tests.

Developed in: WordPress/wordpress-develop#13182

Props jonsurrell, mindctrl.
See #65893.

Built from https://develop.svn.wordpress.org/trunk@63640


git-svn-id: http://core.svn.wordpress.org/trunk@62815 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@sirreal
sirreal deleted the agent/test-order-functions-isolation branch September 17, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants