Skip to content

Tests: Unregister custom taxonomies in get_terms tests teardown - #15094

Closed
rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/65893-isolate-term-getterms
Closed

rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/65893-isolate-term-getterms

Conversation

@rejaulalomkhan

Copy link
Copy Markdown
Member

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, and hierarchical_fields) in wpSetUpBeforeClass(), set_up(), and individual test methods without unregistering them in tear_down() or wpTearDownAfterClass().

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, and hierarchical_fields).
  • wpTearDownAfterClass() to unregister self::$taxonomy registered in wpSetUpBeforeClass().

Testing Instructions

  1. Run vendor/bin/phpunit tests/phpunit/tests/term/getTerms.php -> PASS (114 tests, 378 assertions).
  2. Run 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

  • Tool: Antigravity
  • Model: Gemini 2.5 Pro
  • Role: Assisted in identifying unregistered custom taxonomies in test teardown, formatting the patch, and generating PR documentation.

@github-actions

github-actions Bot commented Oct 28, 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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rejaulalomkhan, mukesh27.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

unregister_taxonomy( 'wptests_tax2' );
unregister_taxonomy( 'wptests_tax_1' );
unregister_taxonomy( 'countries' );
unregister_taxonomy( 'hierarchical_fields' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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()?

@rejaulalomkhan

Copy link
Copy Markdown
Member Author

Thanks for the review, @mukeshpanchal27! Added food, deep, and location to tear_down() in ccfebf3.

@lancewillett

Copy link
Copy Markdown
Member

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 · gpt-6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants