Build/Test Tools: Use strict assertions in the query tests. - #13600
haritpanchal wants to merge 2 commits 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. |
|
The 3 failing jobs (PHP 8.3 / MySQL 8.4 multisite with memcached, PHP 8.3 / MySQL 8.4 with memcached, and PHP 8.5 / MySQL 5.7) appear to be a known infrastructure issue and are not related to this diff. All three jobs hang immediately after the frontend asset build and are terminated by the runner’s 5-minute build timeout: I confirmed the same failure pattern on unrelated PRs as well (e.g. #13601). All substantive checks are passing, including Coding Standards, PHPStan, and the remaining ~90 PHP/DB matrix combinations. |
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.