Skip to content

Tests: Remove redundant registration cleanup from post and query tests - #15189

Open
lancewillett wants to merge 3 commits into
WordPress:trunkfrom
lancewillett:cleanup/registry-posts-queries-65893
Open

lancewillett wants to merge 3 commits into
WordPress:trunkfrom
lancewillett:cleanup/registry-posts-queries-65893

Conversation

@lancewillett

@lancewillett lancewillett commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Core's inherited test setup resets ordinary post types, taxonomies, and non-built-in statuses before each test. Remove duplicate per-test cleanup while retaining scenario-specific unregister calls and unrelated fixture cleanup.

Keep the existing class callbacks in query/fieldsClause.php and query/postStatus.php. Class setup precedes per-test reset, so the per-test reset alone does not justify deleting those callbacks. Leave query/randomContentRedirect.php out of this PR; its cleanup is unchanged.

The deliberate built-in post-type cleanup in post/isPostTypeViewable.php remains untouched. No new tests or assertions.

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

Validation on current trunk with this patch applied independently: PHP syntax and PHPCS passed. Randomized seed 15189 produced identical baseline/patched results: single-site 1,220 tests / 4,085 assertions; multisite 1,238 tests / 4,160 assertions. Four existing PHPUnit expectation-deprecation warnings and one skip remain in both variants. These runs bound compatibility; independent review of class-boundary behavior remains pending.

Prepared with AI assistance (gpt-6).

@lancewillett
lancewillett requested a balanced review from Copilot October 29, 2026 22:03
@github-actions

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 lancewillett.

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.

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 were identified for the removal of redundant test-registration cleanup.

No open issues 🎉

What changed in this PR

This PR simplifies WordPress Core tests by removing registration cleanup that duplicates the base test setup’s resets, following the additions in #65893. Production code and the base test lifecycle remain unchanged.

Changes:

  • Remove cleanup-only teardown overrides for post types, taxonomies, and custom post statuses.
  • Remove class-level post-type cleanup in two query test classes.
  • Preserve assertions, scenario-specific unregister calls, unrelated fixture cleanup, and deliberate built-in post-type cleanup.
File Description
tests/​phpunit/​tests/​user/​theAuthorPosts.php Remove post-type cleanup; retain global cleanup.
tests/​phpunit/​tests/​user/​queryCache.php Remove post-type teardown override.
tests/​phpunit/​tests/​user/​query.php Remove public/private post-type teardown.
tests/​phpunit/​tests/​user/​countUserPosts.php Remove post-type teardown override.
tests/​phpunit/​tests/​query/​taxQuery.php Remove taxonomy and post-type teardown.
tests/​phpunit/​tests/​query/​search.php Remove post-type cleanup; retain query cleanup.
tests/​phpunit/​tests/​query/​results.php Remove handbook post-type teardown.
tests/​phpunit/​tests/​query/​randomContentRedirect.php Remove post-type and taxonomy teardown.
tests/​phpunit/​tests/​query/​postStatus.php Remove class-level and per-test registration cleanup.
tests/​phpunit/​tests/​query/​lazyLoadTermMeta.php Remove taxonomy teardown override.
tests/​phpunit/​tests/​query/​isTerm.php Remove test-taxonomy teardown.
tests/​phpunit/​tests/​query/​fieldsClause.php Remove class-level and per-test post-type cleanup.
tests/​phpunit/​tests/​query/​conditionals.php Remove post-type teardown override.
tests/​phpunit/​tests/​query/​cacheResults.php Remove taxonomy teardown override.
tests/​phpunit/​tests/​post/​wpPublishPost.php Remove taxonomy teardown override.
tests/​phpunit/​tests/​post/​updateTermCountOnTransitionPostStatus.php Remove taxonomy and custom-status teardown.
tests/​phpunit/​tests/​post/​types.php Remove registration cleanup override.
tests/​phpunit/​tests/​post/​randomablePostType.php Remove custom post-type teardown.
tests/​phpunit/​tests/​post/​nav-menu.php Remove post-type and taxonomy teardown.
tests/​phpunit/​tests/​post/​metaRevisions.php Remove custom post-type teardown.
tests/​phpunit/​tests/​post/​getPostClass.php Remove taxonomy teardown override.
tests/​phpunit/​tests/​post/​getPages.php Remove custom-status and post-type teardown.
tests/​phpunit/​tests/​post/​getPageByPath.php Remove post-type teardown override.
tests/​phpunit/​tests/​post/​getLastPostModified.php Remove book post-type teardown.
tests/​phpunit/​tests/​post/​getLastPostDate.php Remove book post-type teardown.
tests/​phpunit/​tests/​post/​getBodyClass.php Remove taxonomy cleanup; retain theme restoration.
tests/​phpunit/​tests/​post.php Remove registration teardown; retain role cleanup.
tests/​phpunit/​tests/​comment/​query.php Remove post-type cleanup; retain fixture cleanup.

Review effort: Balanced

@lancewillett

Copy link
Copy Markdown
Member Author

Narrowed in 7c3292d and 0ea4331: retain the query classes’ existing class callbacks and exclude randomContentRedirect.php from the cleanup. The resulting patch applies to trunk without importing unrelated changes.

Randomized baseline/patched comparisons passed with identical counts: 1,220 tests single-site and 1,238 multisite, with four unchanged expectation-deprecation warnings and one skip. Peter’s independent review remains pending.

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.

🔵 Needs a closer look

Cleanup occurs after the next class’s fixtures are created, so leftover registrations may contaminate them, and the reported single-seed runs do not establish cross-class isolation.

No open issues 🎉

Review effort: Balanced

@lancewillett

Copy link
Copy Markdown
Member Author

Follow-up on the class-boundary concern: I ran the existing GetPages::test_get_pages_post_type immediately before CountUserPosts::test_count_user_posts_post_type_cpt, allowing PHPUnit to run the latter class fixture normally. The same ordered sequence passes on current trunk and with this PR, in single-site and multisite: 2 tests, 4 assertions each.

This is bounded evidence only. The next class fixture can still see a registration before the per-test reset, and the restored class callbacks cover only their named registrations. This comparison did not demonstrate a failing consumer or establish whole-suite class-boundary equivalence. Keeping the independent review hold; no extra cleanup or synthetic tests added.

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

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants