Skip to content

Tests: Document value comparisons in query tests - #13940

Closed
huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:test/query-assert-equals
Closed

huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:test/query-assert-equals

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

Reviewed tests/phpunit/tests/query/ for ticket #64895.

There are 15 calls to assertEquals() across 3 files:

  • tests/phpunit/tests/query/generatePostdata.php:
    • Line 57: Comparing expected $u (WP_User) with $data['authordata'] returned from generate_postdata().
  • tests/phpunit/tests/query/setupPostdata.php:
    • Line 68: Comparing $u (WP_User) with $GLOBALS['authordata'] set by setup_postdata().
    • Line 116: Comparing get_userdata( $users[0] ) (WP_User) with $GLOBALS['authordata'] in the main loop.
    • Line 135: Comparing get_userdata( $users[1] ) (WP_User) with $GLOBALS['authordata'] in the secondary query loop.
    • Line 144: Comparing get_userdata( $users[0] ) (WP_User) with $GLOBALS['authordata'] after wp_reset_postdata().
  • tests/phpunit/tests/query/isTerm.php:
    • 10 calls comparing get_queried_object() / $query->get_queried_object() with taxonomy term objects ($this->tag, $this->cat, $this->uncat, or get_term()).

All 15 calls intentionally compare object instances by value:

  1. generate_postdata(), setup_postdata(), and WP_Query::get_queried_object() instantiate fresh WP_User or WP_Term object instances.
  2. Identity assertions (assertSame()) fail on distinct object instances with Failed asserting that two variables reference the same object.

In accordance with maintainer guidance on Trac #64895 (comments 88 & 93), these intentional loose comparisons are preserved and documented with:
// Keep assertEquals() because the objects are intentionally compared by value.

Testing Instructions

npm run test:php -- --test-suffix .php tests/phpunit/tests/query
composer run lint tests/phpunit/tests/query/generatePostdata.php tests/phpunit/tests/query/isTerm.php tests/phpunit/tests/query/setupPostdata.php

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

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Analyzing assertions and drafting documentation comments. Implementation and test verification were reviewed and executed locally.

Explain why assertEquals() calls intentionally compare WP_Term and WP_User objects by value.

See #64895.
@github-actions

github-actions Bot commented Oct 2, 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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props huzaifaalmesbah.

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

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Oct 2, 2026
Explain why post data and queried term tests retain `assertEquals()` when comparing `WP_User` and `WP_Term` objects by value.

Developed in: #13940

Props huzaifaalmesbah.
See #64895.


git-svn-id: https://develop.svn.wordpress.org/trunk@64069 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 2, 2026
Explain why post data and queried term tests retain `assertEquals()` when comparing `WP_User` and `WP_Term` objects by value.

Developed in: WordPress/wordpress-develop#13940

Props huzaifaalmesbah.
See #64895.

Built from https://develop.svn.wordpress.org/trunk@64069


git-svn-id: http://core.svn.wordpress.org/trunk@63228 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

2 participants