Build/Test Tools: Use strict assertions in the query tests. - #13600
Open
haritpanchal wants to merge 1 commit into
Open
haritpanchal wants to merge 1 commit into
haritpanchal wants to merge 1 commit into
Conversation
|
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 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Reviewed the 5 files claimed on the ticket under
tests/phpunit/tests/query/.8 of 24 loose assertions convert; the rest are legitimate object-identity or
opposite-direction type mismatches.
Converted:
cacheResults.php,results.php(comment_ID cases) —$comment_idis thereturn of the test factory's
wp_insert_comment(), which is(int) $wpdb->insert_id.WP_Comment::$comment_IDis documentednumeric-stringand populated raw from
$wpdb->get_row(), so the expected side is cast tomatch.
results.php—test_post_password():WP_Query's'fields' => 'ids'branch explicitly does
array_map( 'intval', $this->posts ), so results arereal ints. The test's
$onevariable happens to be pre-cast to(string)for use in
post__in, which is unrelated to the result type — cast to(int)at the assertion site instead. Proven necessary by mutation:removing the cast fails with
Expected: Array(0 => '38') / Actual: Array(0 => 38).setupPostdata.php— the one comparison againststrip_ws( $content )converts directly to
assertNotSame(); both sides are plain strings.Left as
assertEquals()/assertNotEquals(), no changes:isTerm.php(10) — every case compares a freshget_queried_object()orget_term()call against a term object obtained earlier in the same test.Proven by mutation: converting one to
assertSame()fails withFailed asserting that two variables reference the same object.— a pure identitymismatch, since two independent term fetches never share the same instance.
generatePostdata.php(1),setupPostdata.php(4) — same identity patternwith
WP_User: a factory-created user vs. a separateget_userdata()callinside
WP_Query::generate_postdata().cacheResults.php(1) — already carries its own comment explaining exactlywhy it must stay
assertNotEquals()rather thanassertNotSame(): the testneeds to ignore object instance IDs and only compare by value.
Testing
PHPCS clean on all 3 changed files. Test-only change; no production code touched.
Trac ticket: https://core.trac.wordpress.org/ticket/64895
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Helping locate candidate files and cross-check each expected literal
against the return-type contract. I reviewed the conversions myself.