Repository navigation
Tests: Unregister custom post types, taxonomies, and post statuses in rest posts controller tests teardown - #15091
Conversation
… rest posts controller tests teardown See #65893.
|
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( 'status' ); | ||
|
|
||
| unset( $wp_post_statuses['testpubstatus'], $wp_post_statuses['testprivtatus'] ); |
There was a problem hiding this comment.
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;.
|
Thanks for the feedback, @mukeshpanchal27! Updated in 3c46bc3 to use |
|
The added cleanup for The inherited reset runs in 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 · |
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 intear_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_statusesto ensure clean test isolation.Testing Instructions
vendor/bin/phpunit --filter WP_Test_REST_Posts_Controller-> PASS (288 tests, 2642 assertions).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
rest-api/rest-posts-controller.php, drafted teardown implementation, and verified via PHPUnit/PHPCS. All changes inspected and verified locally before submission.