Skip to content

Tests: Unregister custom post types, taxonomies, and post statuses in rest posts controller tests teardown - #15091

Closed
rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/65893-isolate-rest-posts-controller
Closed

rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/65893-isolate-rest-posts-controller

Conversation

@rejaulalomkhan

Copy link
Copy Markdown

Description

In tests/phpunit/tests/rest-api/rest-posts-controller.php, tests register several custom post types (youseeme, private-post, not_in_rest, class_not_found, invalid_class, test), a custom taxonomy (status), and custom post statuses (testpubstatus, testprivtatus), but do not clean them up in tear_down(). This leaves custom post types, taxonomies, and post statuses registered in the global state across test runs, which can cause test isolation leaks and side effects in subsequent test runs.

This PR adds teardown logic to tear_down() that unregisters all custom post types and the custom taxonomy, and unsets custom post statuses from $wp_post_statuses to ensure clean test isolation.

Testing Instructions

  1. Run vendor/bin/phpunit --filter WP_Test_REST_Posts_Controller -> PASS (288 tests, 2642 assertions).
  2. Run vendor/bin/phpcs tests/phpunit/tests/rest-api/rest-posts-controller.php -> PASS (0 errors, 0 warnings).

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


Use of AI Tools

  • Tool: Google Antigravity / Gemini 2.5 Pro
  • Purpose: Identified uncleaned custom post types, taxonomy, and post statuses in rest-api/rest-posts-controller.php, drafted teardown implementation, and verified via PHPUnit/PHPCS. All changes inspected and verified locally before submission.

… rest posts controller tests teardown

See #65893.
@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( 'status' );

unset( $wp_post_statuses['testpubstatus'], $wp_post_statuses['testprivtatus'] );

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.

Nit: the test suite has a helper for this, _unregister_post_status() in tests/phpunit/includes/utils.php. It is used in 9 places, while a direct unset( $wp_post_statuses[...] ) appears in 1. Could this use _unregister_post_status( '...' ) for consistency? It would also remove the need for global $wp_post_statuses;.

@rejaulalomkhan

Copy link
Copy Markdown
Author

Thanks for the feedback, @mukeshpanchal27! Updated in 3c46bc3 to use _unregister_post_status() for consistency.

@lancewillett

Copy link
Copy Markdown
Member

The added cleanup for youseeme, private-post, not_in_rest, class_not_found, invalid_class, test, status, testpubstatus, testprivtatus repeats the Core test harness’s registry reset before each test. These registrations do not opt out of that reset, and no existing consumer is shown to fail before it. Closing this cleanup-only proposal as redundant; the existing behavioral tests remain unchanged.

The inherited reset runs in WP_UnitTestCase_Base::set_up().

Thanks for working on test isolation. We can reopen this if an existing test or fixture fails without the cleanup and passes with it under the same environment and order.

AI review · gpt-6

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.

3 participants