Repository navigation
Tests: Unregister custom taxonomies in get_terms tests teardown - #15094
rejaulalomkhan wants to merge 2 commits into
Conversation
|
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:
|
| unregister_taxonomy( 'wptests_tax2' ); | ||
| unregister_taxonomy( 'wptests_tax_1' ); | ||
| unregister_taxonomy( 'countries' ); | ||
| unregister_taxonomy( 'hierarchical_fields' ); |
There was a problem hiding this comment.
Several tests in this file register taxonomies through $tax, and they are not covered here: food (lines 567 and 668), deep (line 713) and location (lines 1151 and 1242). Could they be added to tear_down()?
|
Thanks for the review, @mukeshpanchal27! Added |
|
Closing this cleanup-only proposal: the shared taxonomy reset already handles surviving custom registrations before each test, and this class re-registers its shared taxonomy afterward. Class fixtures run before that reset, but no failing existing consumer at that boundary has been identified. The class cleanup repeats the per-test list. Benefit unproven; please share an existing failing test/order if there is a concrete case to revisit. AI review · |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the taxonomy cleanup changes intended to improve test isolation.
No open issues 🎉
What changed in this PR
This PR improves isolation in Tests_Term_getTerms by cleaning up custom taxonomy registrations, reducing the risk of state leaking into subsequent tests.
Changes:
- Adds per-test teardown to unregister custom taxonomies before calling the parent teardown.
- Adds class-level teardown to unregister the taxonomy created during class setup.
| File | Description |
|---|---|
tests/phpunit/tests/term/getTerms.php |
Adds per-test and class-level taxonomy cleanup. |
Review effort: Balanced
Description
In
Tests_Term_getTerms(tests/phpunit/tests/term/getTerms.php), tests register multiple custom taxonomies (self::$taxonomy/wptests_tax_3,wptests_tax,wptests_tax1,wptests_tax2,wptests_tax_1,countries, andhierarchical_fields) inwpSetUpBeforeClass(),set_up(), and individual test methods without unregistering them intear_down()orwpTearDownAfterClass().This leaks registered taxonomies into the global taxonomy registry, which can cause test pollution and unpredictable state for subsequent test classes.
This PR adds:
tear_down()to unregister all custom taxonomies (self::$taxonomy,wptests_tax,wptests_tax1,wptests_tax2,wptests_tax_1,countries, andhierarchical_fields).wpTearDownAfterClass()to unregisterself::$taxonomyregistered inwpSetUpBeforeClass().Testing Instructions
vendor/bin/phpunit tests/phpunit/tests/term/getTerms.php-> PASS (114 tests, 378 assertions).vendor/bin/phpcs tests/phpunit/tests/term/getTerms.php-> PASS (0 errors, 0 warnings).Trac ticket: https://core.trac.wordpress.org/ticket/65893
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.
Use of AI Tools