Make WordPress Core

Opened 8 months ago

Last modified 8 days ago

#64895 new task (blessed)

Tests: Reduce usage of assertEquals for 7.2

Reported by: desrosj Owned by:
Priority: normal Milestone: 7.2
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

The assertEquals() test method does not check that the types of the expected and actual values match. This can hide subtle bugs especially when the values are falsey.

Tasks:

  • Switch to using assertSame() when the type of the value in the assertion is important
  • Replace overall usage of assertEquals() with type-strict assertion methods, with the aim of potentially removing its usage altogether

To help ease the effort of merging tests, changes should also be made upstream in the Gutenberg repository.

Follow-up to:

Change History (235)

This ticket was mentioned in ​PR #11707 on ​WordPress/wordpress-develop by ​@shreyasikhar26.


6 months ago
#1

  • Keywords has-patch has-unit-tests added

## PR Description

  • Updates multiple PHPUnit tests to use assertSame() instead of assertEquals() to enforce strict type comparisons.
  • Adds an explicit (int) cast for post_author in the bulk edit test to avoid false positives due to string/integer mismatches.
  • Touches tests covering admin bulk edit behavior, REST API endpoints (attachments, global styles, wp-abilities), and theme preview hooks—no production/runtime code changes.

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

## Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot
Used for: Find the files where assertEquals() can be replaced with assertSame().

This ticket was mentioned in ​PR #12583 on ​WordPress/wordpress-develop by ​@Soean.


4 months ago
#2

## What

Replaces loose assertions (assertEquals() / assertNotEquals()) with their strict counterparts (assertSame() / assertNotSame()) across a number of PHPUnit test files.

## Why

Strict assertions additionally check the type of the compared values, making the tests more robust against unintended type coercion and better documenting the expected return types of the functions under test.

## Testing

All affected test files pass locally: OK (71 tests, 669 assertions).

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

This ticket was mentioned in ​PR #12613 on ​WordPress/wordpress-develop by ​@thisismyurl.


4 months ago
#3

Replaces the remaining assertEquals() calls in the REST schema sanitization tests with assertSame().

These assertions are a good fit for strict comparison, because the type of the returned value *is* the thing under test. rest_sanitize_value_from_schema() promises to coerce a value to the type declared in the schema, and most of these cases pass a deliberately mistyped input to prove it does:

$this->assertSame( array( 1.0 ), rest_sanitize_value_from_schema( array( '1' ), $schema ) );

With a loose assertion that test still passes if the sanitizer hands back the uncoerced array( '1' ), so it cannot fail for the one reason it exists.

Worth flagging for review, since it is the easy thing to get wrong here: every schema in these particular tests declares 'type' => 'number', which returns (float), so the expected values are floats rather than integers. That matches the convention already used by test_type_number() at the top of this file, which asserts assertSame( 1.0, ... ).

I checked each expected literal against its own schema rather than swapping the method names mechanically, which also means three values are deliberately left alone:

  • 'd' => '1' in the nested-properties test stays a string, because d has no matching entry in properties, no patternProperties, and additionalProperties is unset, so it is never coerced.
  • The top-level 'b' => 1 in that same test stays an integer for the same reason.
  • 'b' => 1 in test_type_object() likewise stays an integer.

The strict assertions now document that behaviour instead of glossing over it.

Only assertion methods and expected literals changed. The file already used assertSame() for 65 of its assertions, so this makes it consistent throughout.

One disclosure on verification: this box has no Docker/wp-env, so I could not run the full PHPUnit suite locally. I verified each conversion by reading the schema declared in each test and matching the expected literal to the type rest_sanitize_value_from_schema() returns for it, and php -l is clean. I would appreciate a CI run confirming it.

## Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Helping locate candidate files and cross-check each expected literal against the schema type. I reviewed the conversions and take responsibility for the final code.

​@mukesh27 commented on ​PR #12613:


3 months ago
#4

Thanks @thisismyurl for the PR! Can you marge latest trunk in to this branch?

#5 @desrosj
3 months ago

  • Milestone 7.1 → 7.2
  • Summary Tests: Reduce usage of assertEquals for 7.1 → Tests: Reduce usage of assertEquals for 7.2

It looks like this did not receive any attention during the 7.1 cycle.

Since there have been no commits made associated with the work here, I'm going to just punt to 7.2.

#6 follow-up: @lancewillett
2 months ago

Where this stands on trunk today, and how to split it up.

There are 501 assertEquals() calls left in 124 test files. By directory under tests/phpunit/tests/:

calls files directory
113 18 rest-api
59 12 term
40 14 xmlrpc
40 13 (files at the top level)
33 2 interactivity-api
29 1 link
27 3 comment
22 6 user
22 5 query
21 4 multisite
11 8 post
11 3 block-bindings
10 6 option
10 2 pomo
9 3 customize

The remaining 22 directories have seven or fewer each.

Three PRs are already open and need a review before we land them: ​https://github.com/WordPress/wordpress-develop/pull/12583 (approved by @mukesh27), ​https://github.com/WordPress/wordpress-develop/pull/11707 and ​https://github.com/WordPress/wordpress-develop/pull/12613. Landing those first avoids conflicts with new claims.


To claim a directory, comment here with its name, then one PR per directory against this ticket. Please check each of the three open PRs before picking, so you do not redo files they already cover.


The bar for a conversion: switch to assertSame() where the type is part of the function's contract, which is most cases. Where the comparison is loose on purpose, such as objects compared by value or floats, leave assertEquals() and say why in the PR. A conversion that only passes after casting the expected value is a finding about the code under test, and worth a note on the PR rather than a silent cast.

The call for contributors is published on Make/Core and links to this ticket: ​https://make.wordpress.org/core/2026/09/08/join-the-phpunit-test-cleanup-for-7-2/

Last edited 2 months ago by lancewillett (previous) (diff)

#7 in reply to: ↑ 6 @r1k0
2 months ago

Replying to lancewillett:

To claim a directory, comment here with its name, then one PR per directory against this ticket. Please check each of the three open PRs before picking, so you do not redo files they already cover.

Working on customize

This ticket was mentioned in ​PR #13451 on ​WordPress/wordpress-develop by ​@r1k0.


2 months ago
#8

Replace assertEquals with assertSame in Test_WP_Customize_Nav_Menu_Item_Setting::test_value_type_post_type and Test_WP_Customize_Nav_Menu_Item_Setting::test_value_type_taxanomy.

Converted the $expected value to an integer to account for the integer normalization performed by populate_value() when it is called in WP_Customize_Nav_Menu_Item_Setting::value().

For the rest of the assertEquals, I kept them as is for the reasons below:

  1. In
    $this->assertEquals( $expected_sanitized['object_id'], $nav_menu_item->object_id );
    

The $expected_sanitized['object_id'] is an integer while $nav_menu_item->object_id is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
    $this->assertEquals( $expected_sanitized['menu_item_parent'], $nav_menu_item->menu_item_parent );
    

The $expected_sanitized['menu_item_parent'] is an integer while $nav_menu_item->menu_item_parent is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
    foreach ( $post_value as $key => $value ) {
    	$this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" );
    }
    

The $post_value[object_id'] is an integer while $updated_item->object_id is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
    foreach ( $post_value as $key => $value ) {
    	$this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." );
    }
    

The $post_value[object_id'] is an integer while $last_item->object_id is a string returned from post meta by wp_setup_nav_menu_item(), so this assertion cannot be converted to assertSame without resolving the type mismatch.

  1. In
    $this->assertEquals( (object) $term, $menu_object );
    

The (object) $term and $menu_object are objects being compared by value, so this assertion should remain assertEquals() rather than requiring identical object instances with assertSame().

Trac ticket: #64895

## Use of AI Tools
AI assistance: Yes
Tool(s): ChatGPT
Model(s): GPT-5.6
Used for: To track down how values are transformed through sanitize, wp_set_up_nav_menu_item and populate_value to determine which assertions should be converted or retained. The final code changes and decisions were reviewed and made by me.

#9 @lancewillett
2 months ago

In 63604:

Tests: Use assertSame() in WP_Customize_Nav_Menu_Item_Setting tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Where a loose comparison is intentional, inline comments now explain why: post meta returns IDs as strings, and some objects are compared by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13451

Props r1k0, mukesh27.
See #64895.

#11 @r1k0
2 months ago

To claim a directory, comment here with its name, then one PR per directory against this ticket. Please check each of the three open PRs before picking, so you do not redo files they already cover.

Working on Link

#12 @haritpanchal
2 months ago

Working on xmlrpc.

43 loose assertions across 15 files (40 assertEquals(), 3 assertNotEquals()). I checked the three open pull requests first — #12583, #11707 and #12613 — and none of them touch tests/phpunit/tests/xmlrpc/, so there is no overlap to redo.

This ticket was mentioned in ​PR #13503 on ​WordPress/wordpress-develop by ​@haritpanchal.


2 months ago
#13

Replaces the loose assertions in tests/phpunit/tests/xmlrpc with type-strict
counterparts, so the tests assert the type of each value as well as its value.

43 assertions across 15 files: 40 assertEquals() and 3 assertNotEquals().
This is the xmlrpc directory claimed on the ticket. None of the three open
pull requests (#12583, #11707, #12613) touch this directory, so there is no
overlap with work already in review.

## The contract that shapes most of this

XML-RPC deliberately returns IDs as strings, so that they cannot exceed what an
XML-RPC integer can describe. _prepare_term() states it directly:

For integers which may be larger than XML-RPC supports ensure we return strings.

Accordingly, in class-wp-xmlrpc-server.php:

Prepared field Type
_prepare_user() → user_id (string)
_prepare_post() → post_id, post_parent (string)
_prepare_media_item() → attachment_id (string)
_prepare_term() → term_id, term_group, term_taxonomy_id, parent (string)
_prepare_term() → count (int)
_prepare_post() → menu_order (int)
wp_newPost(), mw_newPost() return value (string) $post_id

So assertSame( (string) $id, ... ) here documents an intentional API contract
rather than papering over a type bug. These are not casts added to make a
conversion pass: the tests already assert the same thing themselves, via
pre-existing assertIsString( $result['post_id'] ) and
assertStringMatchesFormat( '%d', $result['term_id'] ) lines that pass on trunk
today. wp/editPost.php likewise already used
assertSame( '', get_post_meta( $post_id, '_thumbnail_id', true ) ).

Values read back from the database follow the same rule and are treated the same
way: WP_Post::$post_author is documented @var string
(@phpstan-var numeric-string|'', default '0'), and get_post_meta() returns
the stored string.

One docblock is imprecise and worth flagging rather than relying on:
WP_Comment::$comment_ID and $comment_post_ID are documented as
@var string|int. _prepare_comment() passes them through with no cast, so the
type comes from the database — strings. The conversions there rest on the file's
own existing assertIsString() assertions, not on that union.

## Two findings, not conversions

1. wp/editProfile.php — test_ignore_email_change() was asserting nothing.

It read $user_data->email. WP_User has no email column — it is
user_email — and email is not in WP_User::$back_compat_keys, so __get()
fell through to get_user_meta( $editor_id, 'email', true ) and returned ''.
The assertion was therefore 'notaneditor@example.com' !== '', which is true no
matter what wp_editProfile() does with the submitted email. The test could
never have caught a regression in the behaviour its name describes.

Changed to user_email, which is the property that holds the value under test.
Confirmed by mutation: with the old expression the actual value is literally
'', and with the fix a flipped assertion fails against the real stored
address.

2. wp/getTerm.php — one assertion stays loose, deliberately.

In test_valid_term(), $term comes from get_term( ..., ARRAY_A ) with
integer term_id/parent, while $result is the prepared struct with those as
strings. A strict comparison of the two arrays would be wrong, so
assertEquals() stays, with a comment recording why, and the individual types
continue to be asserted on the lines below.

The arguments were also reversed — the actual value was being passed in the
expected position — so that is now assertEquals( $term, $result ).

wp/editTerm.php goes the other way for the same reason: WP_Term::$parent is
@var int, so assertEquals( '0', $term->parent ) was comparing against a
string and is now assertSame( 0, $term->parent ).

## Testing

npm run test:php -- --group xmlrpc
OK (348 tests, 1308 assertions)

The whole group is run, not just the changed files, to confirm nothing
collateral broke.

composer lint is clean on all 15 files, and php -l passes on each.

Note for anyone reproducing this: npm run test:php -- tests/phpunit/tests/xmlrpc
reports No tests executed! and exits 0. PHPUnit's default test-file suffix is
*Test.php, and the suffix=".php" in phpunit.xml.dist applies only to the
configured <testsuite>, not to a positional directory argument — so a
directory path silently collects zero tests from this suite. --group xmlrpc
(or explicit file paths) is the working form.

Test-only change; no production code is 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: Inventorying the loose assertions, reading each prepared-struct field
back to its cast in class-wp-xmlrpc-server.php to decide the expected type per
assertion, and drafting this description. I verified every conversion against the
server source and the declared property types, confirmed the three open pull
requests do not overlap this directory, established the editProfile.php finding
from WP_User::$back_compat_keys and __get() and confirmed by mutation that
the replacement assertion can actually fail, ran the full xmlrpc group plus
lint and php -l, and I take responsibility for the result.

​@haritpanchal commented on ​PR #13503:


2 months ago
#14

Thanks — all three applied.

Reproduced both findings by mutation first:

  • _insert_post() / mw_newPost() returning (int) $post_id fails both test_ignore_id tests at the new assertIsString(), and passes without it.
  • _prepare_term() returning all four IDs as integers fails test_valid_term. With the mutation in place but the new assertIsString() lines removed it passes with 16 assertions — matching your result.

--group xmlrpc: OK, 348 tests / 1314 assertions (up 6 from 1308, matching the
6 added). Multisite OK, 349 / 1318. PHPCS 3/3 on the changed files.

#15 @lancewillett
2 months ago

In 63606:

Tests: Use strict assertions in XML-RPC tests.

Use type-strict comparisons for XML-RPC results and persisted values, matching the documented string ID contracts. Add explicit string checks where negative comparisons and numeric-format assertions do not enforce types.

Correct the profile email test to inspect user_email, so it detects an unintended email change. Retain the loose term-array comparison because the internal and XML-RPC representations use different ID types.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13503

Props haritpanchal.
See #64895.

#17 @haritpanchal
2 months ago

Working on option.
10 loose assertions across 6 files (all assertEquals()). I checked the three open pull requests first — #12583, #11707 and #12613 — and none of them touch tests/phpunit/tests/option/, so there is no overlap to redo.

This ticket was mentioned in ​PR #13516 on ​WordPress/wordpress-develop by ​@haritpanchal.


2 months ago
#18

## What

Reviewed the 6 files claimed on the ticket under tests/phpunit/tests/option/.
Only one assertion actually converts to assertSame(); everywhere else the
comparison is intentionally by value, and converting it would either break
identity comparisons on objects or break under multisite.

Converted:

  • siteOption.php — test_update_adds_falsey_value() now asserts assertSame( (string) $value, get_site_option( $key ) ). A fresh DB read returns scalar option values as strings regardless of what was stored, even though $value was set as int 0. Confirmed by mutation: removing the cast fails with Failed asserting that '0' is identical to 0.

Left as assertEquals(), no changes:

  • option.php, siteOption.php (serialized-object test), siteTransient.php (2 object tests + 2 $wpdb->get_row() comparisons), transient.php — all compare a freshly-read stdClass/array against a literal built for the assertion. The DB round trip never returns the same instance, so assertSame() fails on identity alone regardless of the values matching.
  • sanitizeOption.php — test_sanitize_option_permalink_structure() looked convertible and passed single-site (413/413), but running the multisite config caught 4 failures. On invalid input the fallback is get_option( 'permalink_structure' ): on single site the test bootstrap never seeds that option, so it resolves to false; on multisite the site is created via the real installer, which seeds it to '' via populate_options(). One literal can't match both, so it stays loose.
  • wpPrimeOptionCaches.php — already branches on is_object() to pick assertEquals()/assertSame() correctly; no changes needed.

## Testing

npm run test:php -- --group option
413 tests, 1061 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group option
448 tests, 1177 assertions, 0 failures

PHPCS clean on all 6 reviewed 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 and take
responsibility for the final code.

#19 @lancewillett
2 months ago

In 63613:

Tests: Use a strict assertion for a falsey site option.

Assert that an option added with integer zero is returned as the string '0' after flushing the cache, matching the value read from the database.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13516

Props haritpanchal.
See #64895.

#21 @haritpanchal
2 months ago

Working on pomo.

10 loose assertions across 2 files (all assertEquals()). I checked the three open pull requests first — #12583, #11707 and #12613 — and none of them touch tests/phpunit/tests/pomo/, so there is no overlap to redo.

#22 @haritpanchal
2 months ago

pomo reviewed — no conversions needed.

All 10 assertEquals() calls (mo.php: 3, po.php: 7) compare a freshly-constructed Translation_Entry (or an array of them) against one parsed from a file/re-import. These are always different object instances, so assertSame() fails on identity alone regardless of whether the values match — confirmed by mutation: temporarily converting po.php:285 to assertSame() fails with "Failed asserting that two variables reference the same object."

No code change results from this, so no PR. --group pomo: 48 tests, 156 assertions, 0 failures on both single-site and multisite.

#23 @haritpanchal
2 months ago

Working on block-bindings.

11 loose assertions across 3 files (all assertEquals()). I checked the three open pull requests first — #12583, #11707 and #12613 — and none of them touch tests/phpunit/tests/block-bindings/, so there is no overlap to redo.

This ticket was mentioned in ​PR #13520 on ​WordPress/wordpress-develop by ​@haritpanchal.


2 months ago
#24

## What

Reviewed the 3 files claimed on the ticket under tests/phpunit/tests/block-bindings/.
5 of 11 assertEquals() calls convert; the rest are legitimate object-value
comparisons.

Converted:

  • wp-block-get-block-bindings-processor.php — all 4 assertions convert to assertSame(). Each compares a string literal against WP_HTML_Tag_Processor::get_updated_html(), which has a strict : string return-type declaration — both sides are guaranteed strings.
  • wpBlockBindingsRegistry.php — 1 of 5 converts: $result->uses_context is asserted against a plain string array. The constructor stores uses_context unmodified (`$this->$property_name = $property_value` in a generic property-copy loop), so there's no type-coercion in play — a plain array comparison with no object involved.

Left as assertEquals(), no changes:

  • register.php (2 assertions) and wpBlockBindingsRegistry.php (4 of 5) all compare a freshly-new'd WP_Block_Bindings_Source against one the registry constructed and stored internally (register()'s own `new WP_Block_Bindings_Source(...), returned by unregister()`/ get_all_registered()/get_registered()). These are always different object instances with matching property values by design, so assertSame() would fail on identity alone. test_get_all_registered() in register.php additionally mixes identical-reference entries (the global core sources, fetched both sides via get_block_bindings_source()) with non-identical ones (the freshly-registered test sources) in the same array, which rules out converting the whole-array comparison either way.

## Testing

npm run test:php -- --group block-bindings
54 tests, 108 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group block-bindings
54 tests, 108 assertions, 0 failures

PHPCS clean on all 3 reviewed 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 and take
responsibility for the final code.

#25 @lancewillett
8 weeks ago

In 63617:

Tests: Use strict assertions in block bindings tests.

Use assertSame() when comparing updated HTML strings and the registered block binding source context array. Retain value-based comparisons for separately constructed source objects.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13520

Props haritpanchal.
See #64895.

#27 @r1k0
8 weeks ago

In Link strict assertion conversion isn't needed as all the assertEquals calls compare the object instances (and, in some cases, object instances nested in an array) by value, not as the same object.

Verdict: assertEquals assertions in Link are intentional.

#28 @r1k0
8 weeks ago

Working on comment

#29 @haritpanchal
8 weeks ago

Working on interactivity-api

33 loose assertions across 2 files (all assertEquals()).

I checked the three open PRs — #12583, #11707 and #12613. No overlap.

This ticket was mentioned in ​PR #13528 on ​WordPress/wordpress-develop by ​@haritpanchal.


8 weeks ago
#30

## What

Reviewed the 2 files claimed on the ticket under tests/phpunit/tests/interactivity-api/.
All 33 assertEquals() calls convert to assertSame().

  • wpInteractivityAPIDirectivesProcessor.php (32 assertions) — every call compared a string literal against $p, the WP_Interactivity_API_Directives_Processor instance itself, not a string. This only ever worked because PHPUnit falls back to __toString() when comparing a string to an object that defines one — assertSame() would fail on every single one of these (`string !== object`) if the method name were swapped without also fixing the argument. __toString() delegates to get_updated_html(): string (WP_HTML_Tag_Processor, which this class extends), the same strict return-type contract used in the block-bindings/ conversions from this ticket, so each call now explicitly asserts against $p->get_updated_html().
  • wpInteractivityAPI.php (1 assertion) — parse_directive_name() declares `@phpstan-return array{..., suffix: non-empty-string|null, unique_id: non-empty-string|null} and casts every non-null branch with (string)`, so the type is a documented guarantee, not an inference. The two sibling assertions immediately above this one in the same test already use assertSame() for the same structure, so this was an inconsistency fix.

## Testing

npm run test:php -- --group interactivity-api
381 tests, 999 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group interactivity-api
381 tests, 999 assertions, 0 failures

PHPCS clean on both 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 and take
responsibility for the final code.

#31 @lancewillett
8 weeks ago

In 63622:

Tests: Use strict assertions in Interactivity API tests.

Compare updated HTML strings explicitly with assertSame() in the directives processor tests. Use a strict comparison for the sorted directive suffixes and unique IDs, preserving the distinction between strings and null.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13528

Props haritpanchal.
See #64895.

#33 @haritpanchal
8 weeks ago

Working on user.

25 loose assertions across 6 files (23 assertEquals(), 2 assertNotEquals()). I checked the three open PRs — #12583, #11707 and #12613. No overlap.

This ticket was mentioned in ​PR #13545 on ​WordPress/wordpress-develop by ​@haritpanchal.


8 weeks ago
#34

## What

Reviewed the 6 files claimed on the ticket under tests/phpunit/tests/user/.
22 of 25 loose assertions convert (23 assertEquals(), 2 assertNotEquals());
the rest are legitimate object-value comparisons.

Converted:

  • query.php (10 assertions) — WP_User_Query with fields => 'ID' (or '') fills $results via $wpdb->get_col(), so it returns user IDs as numeric strings while the factory returns ints. Expected IDs are now (string)-cast. The two orderby=include tests already noted this in a comment ("assertEquals() respects order but ignores type"), which is removed since the strict assertion now states it.
  • query.php (2 assertions) — the prepare_query() test's assertNotEquals() calls become assertNotSame(); both sides are already the same type.
  • wpGetUsersWithNoRole.php — wp_get_users_with_no_role() documents @return string[] Array of user IDs as strings. The multisite test in the same file already asserted (string) $nobody; the single-site test now matches.
  • wpDeleteUser.php, multisite.php — WP_Post::$post_author is @var string, so these assert (string) $user_id. The assertNotEquals( $user1->ID, $post->post_author ) needed the cast too: without it assertNotSame() compares int to string and can never fail. Confirmed by mutation: with remove_user_from_blog() reassigning to $user1, the cast version fails and the uncast version passes.
  • multisite.php — WP_Site spam/archived/deleted are @var string, so test_get_blogs_of_user() asserts '1'.
  • capabilities.php — in test_user_level_update(), a fresh WP_User reads user_level from user meta via __get(), so it is '2'. After set_role(), update_user_level_from_caps() assigns an int, which is why the sibling assertions already use assertSame( 7, ... ). Matches the documented @phpstan-property int|numeric-string|'' $user_level; a comment records the asymmetry.

Left as assertEquals(), no changes:

  • capabilities.php — test_wp_roles_init_action() compares a freshly constructed WP_Role against the one WP_Roles built; different instances by design.
  • updateUserCaches.php (2 assertions) — compare a $wpdb->get_row() object against the cached row. WP_Object_Cache clones objects on set and get, so assertSame() fails on identity alone.

## Testing

npm run test:php -- --group user
1344 tests, 4534 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group user
1403 tests, 5000 assertions, 0 failures

Both match a trunk baseline; the 5 warnings in each run are pre-existing and unrelated.

PHPCS clean on all 5 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
## What

Reviewed the 6 files claimed on the ticket under tests/phpunit/tests/user/.
22 of 25 loose assertions convert (23 assertEquals(), 2 assertNotEquals());
the rest are legitimate object-value comparisons.

Converted:

  • query.php (10 assertions) — WP_User_Query with fields => 'ID' (or '') fills $results via $wpdb->get_col(), so it returns user IDs as numeric strings while the factory returns ints. Expected IDs are now (string)-cast. The two orderby=include tests already noted this in a comment ("assertEquals() respects order but ignores type"), which is removed since the strict assertion now states it.
  • query.php (2 assertions) — the prepare_query() test's assertNotEquals() calls become assertNotSame(); both sides are already the same type.
  • wpGetUsersWithNoRole.php — wp_get_users_with_no_role() documents @return string[] Array of user IDs as strings. The multisite test in the same file already asserted (string) $nobody; the single-site test now matches.
  • wpDeleteUser.php, multisite.php — WP_Post::$post_author is @var string, so these assert (string) $user_id. The assertNotEquals( $user1->ID, $post->post_author ) needed the cast too: without it assertNotSame() compares int to string and can never fail. Confirmed by mutation: with remove_user_from_blog() reassigning to $user1, the cast version fails and the uncast version passes.
  • multisite.php — WP_Site spam/archived/deleted are @var string, so test_get_blogs_of_user() asserts '1'.
  • capabilities.php — in test_user_level_update(), a fresh WP_User reads user_level from user meta via __get(), so it is '2'. After set_role(), update_user_level_from_caps() assigns an int, which is why the sibling assertions already use assertSame( 7, ... ). Matches the documented @phpstan-property int|numeric-string|'' $user_level; a comment records the asymmetry.

Left as assertEquals(), no changes:

  • capabilities.php — test_wp_roles_init_action() compares a freshly constructed WP_Role against the one WP_Roles built; different instances by design.
  • updateUserCaches.php (2 assertions) — compare a $wpdb->get_row() object against the cached row. WP_Object_Cache clones objects on set and get, so assertSame() fails on identity alone.

## Testing

npm run test:php -- --group user
1344 tests, 4534 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group user
1403 tests, 5000 assertions, 0 failures

Both match a trunk baseline; the 5 warnings in each run are pre-existing and unrelated.

PHPCS clean on all 5 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 and take
responsibility for the final code.

#35 @lancewillett
8 weeks ago

In 63632:

Tests: Use strict assertions in user tests.

Replace loose comparisons with strict assertions for user query results, post reassignment, site flags, and user levels. Cast expected IDs to strings to match database return values and preserve meaningful negative comparisons.

Retain object-value comparisons where distinct instances are expected, and explain the user level type before a role change.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13545

Props haritpanchal.
See #64895.

#37 @haritpanchal
8 weeks ago

Working on multisite

23 loose assertions across 4 files (21 assertEquals(), 2 assertNotEquals()). I checked the three open pull requests first — #12583, #11707 and #12613. No overlap.

This ticket was mentioned in ​PR #13558 on ​WordPress/wordpress-develop by ​@haritpanchal.


8 weeks ago
#38

What

Reviewed the 4 files claimed on the ticket under tests/phpunit/tests/multisite/.
21 of 23 loose assertions convert (21 assertEquals(), 2 assertNotEquals()).

Converted:

  • bootstrap.php, getBlogDetails.php, network.php (2 of 4), and several in site.php — all compare an expected int against WP_Site::$blog_id (or the same object accessed via get_dashboard_blog()). $blog_id is a raw public property populated directly from $wpdb->get_row() with no cast (WP_Site::__construct()), so it's always a string; the int side is cast to match.
  • site.php — test_wp_insert_site() / test_wp_update_site(): their data providers used int literals (0/1/2) for WP_Site::$public, $archived, $mature, $spam, $deleted, $lang_id, and $site_id, but these are also raw DB-string properties. Confirmed with a live debug dump (gettype() per key under the actual multisite run) rather than assuming, then corrected the data providers' literals to strings before converting the assertions. Proven necessary by mutation: reverting one row back to an int literal fails with Failed asserting that '0' is identical to 0.
  • site.php — $cap_key (WP_User::$cap_key, always a string) and WP_Site::$path comparisons convert assertNotEquals() → assertNotSame() directly; both sides are already the same type.

Left as assertEquals(), no changes:

  • network.php (2) — get_blog_count() is backed by get_network_option(), whose return type isn't a stable contract here: it comes back as a string on a fresh DB read but as an int when served from a warm in-request cache. Confirmed empirically — converting both to assertSame() failed in opposite directions on the two tests (1 vs '1' and '3' vs 3), so they stay loose.
  • site.php (6) — all compare a wp_cache_get() result (or the object just passed to wp_cache_set()) against the freshly-cached value. WP_Object_Cache::set() and get() both clone any object argument (confirmed in class-wp-object-cache.php), so identity can never match even when it's the exact same logical value.

Testing

npm run test:php -- --group multisite
32 tests, 43 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group multisite
798 tests, 1901 assertions, 0 failures (2 pre-existing, unrelated skips)

PHPCS clean on all 4 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.

#39 @lancewillett
8 weeks ago

In 63638:

Tests: Use strict assertions in multisite tests.

Compare site IDs and persisted site properties with strict assertions, matching their string types. Update expected provider values while preserving integer inputs and the integer network_id property checks.

Use strict negative comparisons for capability keys and site paths. Retain value-based comparisons for cached objects and network counts with variable return types.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13558

Props haritpanchal.
See #64895.

#41 @haritpanchal
8 weeks ago

Working on query.

24 loose assertions across 5 files (22 assertEquals(), 2 assertNotEquals()). I checked the three open pull requests first — #12583, #11707 and #12613 — and none of them touch tests/phpunit/tests/query/, so there is no overlap to redo.

This ticket was mentioned in ​PR #13593 on ​WordPress/wordpress-develop by ​@r1k0.


8 weeks ago
#42

  • In comment/commentsTemplate.php

Changed assertEquals to assertSame because the expected and actual values produce identical arrays.

  • In comment/pingback.php Tests_Comment_Pingback::test_pingback - Changed assertEquals to assertSame because the expected and actual values produce identical arrays.


Tests_Comment_Pingback::test_pingback_no_ping_back & Tests_Comment_Pingback::test_pingback_error_response - Changed assertEquals to assertSame because the expected and actual values produce empty arrays.

  • In comment/query.php

Test_Comment_Query::test_get_comments_for_post - Changed assertEquals to assertSame and cast the expected value ($comment_id) from an integer to a string because the WP_Comment::comment_post_ID is a numeric string.

Test_Comment_Query::test_orderby_meta - Changed assertEquals to assertSame and cast the expected value ($post_id) from an integer to a string because the WP_Comment::comment_ID is a numeric string.

Test_Comment_Query::test_get_comments_by_user - Changed assertEquals to assertSame and cast the expected value ($users) from an integer to a string because the WP_Comment::user_id is a numeric string.

Test_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_ASC and Test_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_DESC - Changed assertEquals to assertSame and cast the expected array value ($comments) from an integer to a string because the WP_Comment::comment_ID is a numeric string.

Test_Comment_Query::test_comment_query_object - Kept assertEquals because the expected and actual output give different object instances but the same values.

Trac ticket: #64895

Use of AI Tools

N/A

#43 @r1k0
8 weeks ago

Working on term

This ticket was mentioned in ​PR #13600 on ​WordPress/wordpress-develop by ​@haritpanchal.


8 weeks ago
#44

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_id is the return of the test factory's wp_insert_comment(), which is `(int) $wpdb->insert_id. WP_Comment::$comment_ID is documented numeric-string` and populated raw from $wpdb->get_row(), so the expected side is cast to match.
  • results.php — test_post_password(): WP_Query's 'fields' => 'ids' branch explicitly does array_map( 'intval', $this->posts ), so results are real ints. The test's $one variable 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 against strip_ws( $content ) converts directly to assertNotSame(); both sides are plain strings.

Left as assertEquals()/assertNotEquals(), no changes:

  • isTerm.php (10) — every case compares a *fresh* get_queried_object() or get_term() call against a term object obtained earlier in the same test. Proven by mutation: converting one to assertSame() fails with `Failed asserting that two variables reference the same object.` — a pure identity mismatch, since two independent term fetches never share the same instance.
  • generatePostdata.php (1), setupPostdata.php (4) — same identity pattern with WP_User: a factory-created user vs. a separate get_userdata() call inside WP_Query::generate_postdata().
  • cacheResults.php (1) — already carries its own comment explaining exactly why it must stay assertNotEquals() rather than assertNotSame(): the test needs to ignore object instance IDs and only compare by value.

Testing

npm run test:php -- --group query
1896 tests, 4436 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group query
1896 tests, 4436 assertions, 0 failures

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.

This ticket was mentioned in ​PR #13601 on ​WordPress/wordpress-develop by ​@r1k0.


8 weeks ago
#45

  • In comment/commentsTemplate.php

Changed assertEquals to assertSame because the expected and actual values produce identical arrays.

  • In comment/pingback.php Tests_Comment_Pingback::test_pingback - Changed assertEquals to assertSame because the expected and actual values produce identical arrays.


Tests_Comment_Pingback::test_pingback_no_ping_back & Tests_Comment_Pingback::test_pingback_error_response - Changed assertEquals to assertSame because the expected and actual values produce empty arrays.

  • In comment/query.php

Test_Comment_Query::test_get_comments_for_post - Changed assertEquals to assertSame and cast the expected value ($post_id) from an integer to a string because the WP_Comment::comment_post_ID is a numeric string.

Test_Comment_Query::test_orderby_meta - Changed assertEquals to assertSame and cast the expected value ($comment_id) from an integer to a string because the WP_Comment::comment_ID is a numeric string.

Test_Comment_Query::test_get_comments_by_user - Changed assertEquals to assertSame and cast the expected value ($users) from an integer to a string because the WP_Comment::user_id is a numeric string.

Test_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_ASC and Test_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_DESC - Changed assertEquals to assertSame and cast the expected array value ($comments) from an integer to a string because the WP_Comment::comment_ID is a numeric string.

Test_Comment_Query::test_comment_query_object - Kept assertEquals because the expected and actual output give different object instances but the same values.

Trac ticket: #64895

Use of AI Tools

N/A

[!NOTE]
This is a redo of #13593 because of mishaps on my end.

​@r1k0 commented on ​PR #13593:


8 weeks ago
#46

I had issues with this branch. I opened another one: #13601

​@haritpanchal commented on ​PR #13600:


7 weeks ago
#47

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: The action 'Build WordPress' has timed out after 5 minutes.

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.

​@lancewillett commented on ​PR #13600:


7 weeks ago
#48

@haritpanchal These changes look good. Could you please prepare a separate PR for Copilot’s suggestion to use assertSameSets() with integer expected IDs for the remaining comparisons in test_post_password()?

​@lancewillett commented on ​PR #12613:


7 weeks ago
#50

Changes look good to land.

#51 @lancewillett
7 weeks ago

In 63772:

Tests: Use strict assertions in query tests.

Match expected comment IDs to their string values and post query IDs to their integer values. Use a strict comparison for the post content check.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13600

Props haritpanchal.
See #64895.

#53 @lancewillett
7 weeks ago

In 63773:

Tests: Use strict assertions for REST schema sanitization.

Verify both the values and types returned by schema sanitization. Use float expectations for number schemas while preserving original types for properties without a matching schema.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/12613

Props thisismyurl, mukesh27.
See #64895.

#55 @lancewillett
7 weeks ago

In 63774:

Tests: Use strict assertions in comment tests.

Compare comment query IDs as strings and use strict assertions for pagination offsets and pingback results. Explain why comment object arrays retain value-based comparison.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13601

Props r1k0, mukesh27.
See #64895.

This ticket was mentioned in ​PR #13649 on ​WordPress/wordpress-develop by ​@haritpanchal.


7 weeks ago
#57

Follow-up to #13600 (merged as 63772),
per Copilot's review suggestion and @lancewillett's request on that PR.

test_post_password() had 5 remaining assertEqualSets() calls comparing
$two/$three/$one (pre-cast to (string) for use in post__in) against
WP_Query's 'fields' => 'ids' results, which are real ints
(array_map( 'intval', ... )). assertEqualSets() sorts both sides and then
compares loosely, so the type mismatch went unnoticed the same way the
already-converted assertEquals() calls in this method did.

Converted all 6 calls ($result1, $result3, $result7, $result8,
$result9, $result11) to assertSameSets() — the strict counterpart
already defined in abstract-testcase.php — with the expected IDs cast to
(int) at each call site.

Proven necessary by mutation: removing one cast fails with

--- Expected
+++ Actual
@@ @@
 Array &0 (
- 0 => '39'
- 1 => '40'
- 0 => 39
- 1 => 40
 )

Testing

npm run test:php -- --filter test_post_password
3 tests, 25 assertions, 0 failures

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter test_post_password
3 tests, 25 assertions, 0 failures

npm run test:php -- --group query
1896 tests, 4436 assertions, 0 failures (single-site and multisite)

PHPCS clean. 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: Implementing the requested conversion and verifying it by mutation. I reviewed the change

This ticket was mentioned in ​PR #13651 on ​WordPress/wordpress-develop by ​@Soean.


7 weeks ago
#58

Four assert() calls in the test suite sit in WP_UnitTestCase subclasses. All four are better expressed as assertIsInt(), assertIsString() and assertInstanceOf(). Those count towards the assertion tally and report through PHPUnit's normal failure path, naming the value and the type it was expected to have, instead of raising a bare AssertionError.

Two further calls stay as they are. Neither is in a TestCase, one sitting in an anonymous class extending WP_HTML_Processor and the other in a PHPStan node visitor, so no assertion method is in scope. They gain a description instead, which an AssertionError otherwise lacks entirely.

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

#59 @haritpanchal
7 weeks ago

Working on top-level files

34 loose assertions across 10 files (33 assertEquals(), 1 assertNotEquals()): term.php, taxonomy.php, cron.php, user.php, query.php, cache.php, theme.php, comment.php, json-schema.php, rest-api.php. I checked the three open pull requests first - #12583, #11707 and #12613, and excluded functions.php, post.php and theme-previews.php since those are already claimed by #12583/#11707.

This ticket was mentioned in ​PR #13652 on ​WordPress/wordpress-develop by ​@haritpanchal.


7 weeks ago
#60

What

Reviewed the 10 top-level files claimed on the ticket under tests/phpunit/tests/
(excluding functions.php, post.php, and theme-previews.php, already
claimed by #12583/#11707). 19 of 34 loose assertions convert across 5 files;
the other 5 files need no changes.

Converted:

  • term.php (7) — get_option( 'default_category' ) returns a string (confirmed via a live debug dump: `string 'default_category type=string value=\'1\) while $post->post_category[0]` is a real int, already established by the existing assertSame() calls a few lines below in the same test. term_exists() with no taxonomy argument explicitly `return (string) $_term;. One genuine finding: test_wp_set_term_objects_finds_ term_name_with_special_characters() calls wp_set_object_terms()` twice with identical arguments and asserted the two results were equal — but wp_insert_term()'s brand-new-term path does `$tt_id = (int) $wpdb->insert_id while its own early-return path (and term_exists()`, hit on the second call since the term now exists) returns a numeric-string. A real asymmetry in the function's contract depending on whether the term already existed, not a bug to hide — the expected side is cast to match.
  • taxonomy.php (4) — get_objects_in_term() returns $wpdb->get_col() results directly with no intval() mapping (unlike the term_ids it queries by, a few lines above in the same function), so it's always strings.
  • user.php (5 of 7) — WP_User::$ID is a real declared property, cast to int in init(). But WP_User::get_data_by() and the userslugs cache entry set by update_user_caches() both use the raw DB row instead (confirmed by reading update_user_caches(), which explicitly reassigns $user = $user->data — the raw stdClass — before caching), so ID there is a string. use_ssl and user_level are meta-backed and always come back as strings.
  • comment.php (1) — wp_list_pluck( $found, 'comment_ID' ) returns numeric strings (WP_Comment::$comment_ID), while the factory-created comment IDs used as the expected value are ints.
  • rest-api.php (2, plus a data-provider fix) — a mutation-proven finding: data_rest_parse_date() computed one expected value as `gmmktime(...) + 5.5 * HOUR_IN_SECONDS, which PHP evaluates as a **float** (1484586000.0`) even though the value is whole, while rest_parse_date() always returns int. Confirmed by running the converted assertion before fixing it: Failed asserting that 1484586000 is identical to 1484586000.0. Fixed by wrapping the data-provider row in (int). The other conversion ($_SERVER['SERVER_NAME'] vs parse_url( home_url(), PHP_URL_HOST )) is a plain string-vs-string comparison, no cast needed.

Left as assertEquals()/assertNotEquals(), no changes (5 files):

  • cron.php (7) — wp_get_scheduled_event() always does `$event = (object) array(...); return $event;, a fresh stdClass` every call, never the same instance as the test's own (object) array(...).
  • query.php (2) — the familiar get_queried_object()/get_term() identity-mismatch pattern already established on this ticket for the query/ directory.
  • cache.php (1) — compares a freshly new WP_Object_Cache() against a different global instance created by wp_cache_init().
  • theme.php (2) — wp_get_theme() always does return new WP_Theme(...), confirmed by reading the source; two separate calls are always different instances (unlike the *deprecated* get_theme()/get_themes() wrappers a few lines above in the same file, which cache in a static $wp_themes array and already use assertSame() successfully).
  • json-schema.php (1) — compares a fresh new stdClass() (representing an empty JSON object) against another fresh new stdClass() built by wp_prepare_json_schema_for_client(); two property-less objects of the same class are never === to each other regardless of content.
  • user.php (2 of 7) — test_user_properties() and test_update_user() each loop over a mix of real declared properties (int, e.g. ID) and meta-backed keys (string) with the same generic assertion, so the type genuinely differs per iteration — the same class of finding as multisite/site.php's test_wp_insert_site() earlier on this ticket.

Testing

Each of the 10 files individually, single-site and multisite (class-name
filters used for json-schema.php/rest-api.php since PHPUnit can't infer
a class name from a hyphenated filename):

term.php: 49 tests, 113 assertions
taxonomy.php: 68 tests, 186 assertions
cron.php: 52 tests, 193 assertions
user.php: 122 tests, 416 assertions (1 pre-existing, unrelated skip)
query.php: 40 tests, 104 assertions
cache.php: 36 tests, 101 assertions
theme.php: 93 tests, 5537 assertions (15 pre-existing, unrelated skips)
comment.php: 90 tests, 187 assertions
json-schema.php (Tests_JSON_Schema): 13 tests, 65 assertions
rest-api.php (Tests_REST_API): 405 tests, 846 assertions

All 0 failures, both single-site and multisite. PHPCS clean on all 5 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: Implementing the requested conversion and verifying it by mutation. I reviewed the changes myself.

#61 @haritpanchal
7 weeks ago

Working on post.

14 loose assertions across 9 files (11 assertEquals(), 3 assertNotEquals()). I checked the three open pull requests first — #12583 and #11707 (the third, #12613, has since landed) — and none of them touch tests/phpunit/tests/post/, so there is no overlap to redo.

Last edited 7 weeks ago by haritpanchal (previous) (diff)

This ticket was mentioned in ​PR #13659 on ​WordPress/wordpress-develop by ​@haritpanchal.


7 weeks ago
#62

What

Reviewed the 9 files claimed on the ticket under tests/phpunit/tests/post/.
8 of 14 loose assertions convert across 6 files; the other 3 files need no
changes.

Converted:

  • objects.php — the same get_option( 'default_category' ) (string) vs. post_category[0] (int) pattern already established for term.php on this ticket. The second conversion (esc_js() vs. post_title) is a plain string-vs-string comparison.
  • nav-menu.php — $t (a factory-created term ID, int) vs. $menu_items[0]->object_id, which is post-meta-backed (_menu_item_object_id) and always a string. Proven necessary by mutation: removing the cast fails with `Failed asserting that '10' is identical to 10.`
  • revisions.php (2) — WP_Post::$post_author is documented `@var string, and get_post_meta( ..., true )` always returns a string for a single meta value. The second one proven necessary by mutation: Failed asserting that '2' is identical to 2.
  • thumbnails.php — _wp_preview_post_thumbnail_filter() explicitly does return (string) $thumbnail_id; on its success path (traced directly in revision.php).
  • types.php (1 of 2) — register_post_type()'s args processing does $args['exclude_from_search'] ??= ! $args['public'];, a real boolean negation, so both sides are already the same type — no cast needed.

Left as assertEquals(), no changes (3 files):

  • wpCountAttachments.php — wp_count_attachments() and the cached value it compares against are both (object) $counts, but `WP_Object_Cache:: set()/get()` clone objects (the same pattern established elsewhere on this ticket), so identity can never match.
  • meta.php (2) — get_post_meta_by_id() (via get_metadata_by_mid()) does a fresh $wpdb->get_row() every call — a new stdClass instance each time, so identity alone rules out assertSame() regardless of property types.
  • getPageByPath.php (2) — both compare a get_post()-obtained WP_Post against a separate get_page_by_path()-returned one; the familiar get_post()/object-cache-clone identity pattern from earlier on this ticket.
  • types.php (1 of 2) — test_get_post_type_object_casting(): get_post_type_labels() calls _get_custom_object_labels(), which mutates the registered post type object's ->labels property from stdClass to a plain array as a side effect ($data_object->labels = (array) $data_object->labels;, traced in post.php). $before (captured pre-mutation) is an object; $after (post-mutation) is an array — genuinely different *types* by design, so assertSame() would always fail regardless of content. The test's whole point is verifying the values survive that container change.

Testing

npm run test:php -- --group post
# 951 tests, 2701 assertions, 0 failures (1 pre-existing, unrelated skip)

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group post
# 953 tests, 2703 assertions, 0 failures (1 pre-existing, unrelated skip)

PHPCS clean on all 6 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.

#63 @lancewillett
7 weeks ago

In 63872:

Tests: Use strict set assertions for password query IDs.

Use assertSameSets() for the remaining multi-result comparisons in test_post_password(). Cast expected IDs to integers to match WP_Query's ID return values while preserving order-independent comparisons.

Follow-up to [63772].

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13649

Props haritpanchal.
See #64895.

#64 @lancewillett
7 weeks ago

In 63873:

Tests: Use strict assertions in post tests.

Match expected category IDs to integers and menu item, revision author, post meta, and thumbnail IDs to strings. Use strict comparisons for cache invalidation and filtered post titles.

Assert that a non-public post type is excluded from search with assertTrue(), checking both the expected boolean value and type.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13659

Props haritpanchal.
See #64895.

#67 @lancewillett
7 weeks ago

In 63880:

Tests: Use strict assertions in additional test cases.

Replace loose equality and inequality assertions in selected core tests with strict comparisons where the fixtures and surrounding assertions establish the expected types.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/12583

Props soean, mukesh27, desrosj.
See #64895.

#69 @lancewillett
7 weeks ago

In 63882:

Tests: Use strict assertions in top-level test files.

Normalize expected IDs to match the string or integer values returned by comment, taxonomy, term, and user APIs. Use strict REST API comparisons and correct the fractional-hour date fixture to expect an integer timestamp.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13652

Props haritpanchal, desrosj.
See #64895.

#71 @haritpanchal
7 weeks ago

Working on rest-api

50 loose assertions across 12 files (35 assertEquals(), 15 assertNotEquals()). This directory has 112 calls across 17 files total, but I'm excluding 5 files —

  • rest-attachments-controller.php,
  • rest-global-styles-controller.php,
  • wpRestAbilitiesV1CategoriesController.php,
  • wpRestAbilitiesV1ListController.php,
  • wpRestAbilitiesV1RunController.php

since they're still covered by the open PR #11707. #12583 and #12613 already landed and their conversions are reflected in the counts above, so there's no overlap with those two.

This ticket was mentioned in ​PR #13683 on ​WordPress/wordpress-develop by ​@haritpanchal.


7 weeks ago
#72

What

Reviewed the 12 files claimed on the ticket under tests/phpunit/tests/rest-api/
(excluding 5 files still covered by the open PR #11707: rest-attachments-controller.php,
rest-global-styles-controller.php, wpRestAbilitiesV1CategoriesController.php,
wpRestAbilitiesV1ListController.php, wpRestAbilitiesV1RunController.php).

44 of 50 loose assertions convert; 6 stay loose as legitimate object-value comparisons.

Converted

rest-posts-controller.php (15/15) — $data['author'], $data['id'], and the
date/date_gmt/modified/modified_gmt fields are all real int/string types per
class-wp-rest-posts-controller.php ((int) $post->post_author, $post->ID sanitized
to int, mysql_to_rfc3339() returning string|null), so these convert directly to
assertNotSame(). Two calls needed a cast: get_post_meta( $post_id, 'my_custom_int', true )
always returns the raw DB string '123', not int 123 — assertEquals( 123, ... ) was
passing on loose coercion. Confirmed by mutation: reverting the cast to 123 fails with
Failed asserting that '123' is identical to 123.

rest-comments-controller.php (11/11) — same 123/'123' meta pattern as posts.
check_comment_data()'s four property comparisons (comment_ID, comment_post_ID,
comment_parent, user_id) compare WP_Comment's raw numeric-string properties against
the REST response's (int)-cast fields, so each needs (int) on the expected side.
Confirmed by mutation: removing one cast fails with
Failed asserting that 2 is identical to '2'. One (comment_approved) is a plain string
cast ('1'), and one line was simply inconsistent with its own file — the sibling
assertion on the line above already used the same (string) cast with assertSame().

rest-users-controller.php (5/9) — post_author reassignment checks follow the same
WP_Post::$post_author string contract established earlier on this ticket (props
haritpanchal, changeset 63632), plus the same 123/'123' meta pattern. Left unconverted:
two comparisons against new stdClass() and two comparisons of (object) $user->allcaps /
(object) $user->caps against the controller's own independently-cast copy — both sides are
always different object instances by construction, so assertSame() would fail on identity
alone regardless of matching properties.

rest-autosaves-controller.php (3/3), rest-revisions-controller.php (1/1) — the
shared check_get_autosave_response() / check_get_revision_response() helpers compare
$autosave->post_author / $revision->post_author (string) against the REST response's
(int)-cast author field; both need the same (int) cast, confirmed by mutation
(Failed asserting that 2 is identical to '2'.).

rest-post-meta-fields.php (3/3), rest-term-meta-fields.php (3/3) — identical setup
in both files: test_custom_schema is registered with show_in_rest.schema.type => 'number',
so the REST-exposed value is sanitized to (float) — same finding as PR #12613's REST schema
sanitization work. assertSame( 3.0, ... ) is required, not 3; confirmed by mutation
(Failed asserting that 3.0 is identical to 3.). The two raw get_post_meta()/get_term_meta()
reads in the same tests stay string-cast ('3', '2'), since those bypass the REST schema
entirely.

rest-server.php (1/1) — test_default_param_is_overridden() sets
'foo' => 123 (a real int, not a query string) directly via set_query_params(), and no
'type' is declared for the foo arg, so no sanitization runs. The original
assertEquals( '123', $request['foo'] ) was passing only because of loose int/string
coercion — the expected literal was simply wrong. Confirmed by first converting straight to
assertSame( '123', ... ), which failed with
Failed asserting that 123 is identical to '123'.; fixed to assertSame( 123, ... ) to
match the actual (and intended) behavior — the test is about default-value override, not
type coercion.

rest-themes-controller.php (1/1) — wp_list_pluck( $data, 'stylesheet' ) always
returns an array of plain strings; direct conversion.

rest-request.php (1/1, not a direct swap) — test_alternate_json_content_type()'s
has_json_params assertion is a trap: when the JSON body is parsed, get_param() returns
real bool true; when it isn't, get_param() returns null (a missing key), never false.
A direct assertSame( $accept_json, ... ) swap looks correct but actually breaks the two
false data sets, since null !== false. Confirmed by mutation: swapping to a plain
assertSame() fails 2 of 6 data sets with Failed asserting that null is identical to false.
Fixed with an explicit branch — assertTrue() when JSON is expected, assertNull()
otherwise — so each branch asserts the value it actually gets, the same fix shape as the
assertTrue() change requested on PR #13659.

Left as assertEquals(), no changes

  • rest-users-controller.php (4) — $data['capabilities']/$data['extra_capabilities'] vs new stdClass(), and vs (object) $user->allcaps / (object) $user->caps: always distinct object instances, compared by value only.
  • rest-block-renderer-controller.php (1) — two independent json_decode() calls (without the true arg) produce distinct stdClass trees each time; compared by value only.
  • wpRestTemplatesController.php (1) — compares against new stdClass(); same identity issue as above.

Testing

npm run test:php -- --group restapi
Tests: 3566, Assertions: 16298, Errors: 1 (pre-existing, unrelated — see below), Skipped: 6

node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c tests/phpunit/multisite.xml --group restapi
Tests: 3601, Assertions: 16428, Errors: 1 (same pre-existing error), Skipped: 6

npm run test:php -- --group restapi-autosave / restapi-themes (single-site and multisite)
All OK, no failures

The one error (Test_oEmbed_Controller::test_proxy_with_classic_embed_provider, `Attempt
to read property "queue" on null) is in tests/oembed/controller.php`, a file untouched by
this PR. Confirmed pre-existing by stashing this branch's changes and re-running the same
test directly against trunk — it fails identically there.

Every risky conversion above (the four 123/'123' meta findings, the four (int)-cast
post_author/comment-property findings, the 3.0 schema-float finding, the rest-server.php
literal-mismatch finding, and the rest-request.php null-vs-false trap) was proven by
mutation: reverting the fix and confirming the test fails for the expected reason, then
restoring it.

PHPCS clean on all 10 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: Digging through this directory turned up a few things worth flagging beyond the mechanical conversion — get_param() returning null instead of false when a param is simply absent (which a naive strict-assertion swap would have broken outright), get_post_meta()/get_term_meta() silently returning strings for values stored as ints, and a schema declared type => 'number' quietly coercing to float on the way out. One assertion (rest-server.php) turned out to be checking the wrong literal type entirely, just masked by loose comparison the whole time. Each of these was confirmed by mutation before I trusted it. I take responsibility for the result.

#73 @lancewillett
7 weeks ago

In 63896:

Tests: Use strict assertions in REST API tests.

Use type-strict assertions for REST response values and metadata. Match expected types to raw database values and REST schema sanitization, and explicitly check for null when JSON parameters are absent.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13683

Props haritpanchal.
See #64895.

#75 @haritpanchal
7 weeks ago

Working on the remaining small directories.

45 loose assertions across 26 files (40 assertEquals(), 5 assertNotEquals()), covering the
directories that were never individually claimed: admin (7), formatting (6), abilities-api (5),
bookmark (5), html-api (4), ajax (2), db (2), dependencies (2), sitemaps (2), theme (2), and one
each in block-supports, block-templates, blocks, compat, feed, functions, http and l10n
.

I checked the open pull requests first. #11707 is rest-api only. #13572 is post only. #13651
touches tests/phpunit/tests/dependencies/scripts.php, which is also in this scope, but it
converts the bare assert() calls near the top of that file while the two assertions here are at
lines 3106 and 3894, so there is no overlap to redo.

This ticket was mentioned in ​PR #13756 on ​WordPress/wordpress-develop by ​@haritpanchal.


7 weeks ago
#76

What

Reviewed the remaining directories claimed on the ticket — the ones that were never
individually claimed, each holding seven or fewer loose assertions. 25 of 45 convert across 19
files; the other 20 are legitimate object-value comparisons and stay loose.

Findings

abilities-api/wpRegisterAbility.php — the test asserted a value the API never returns.
test_register_valid_ability() expected 'idempotent' => false, but WP_Ability declares
'idempotent' => null in $default_annotations and prepare_properties() fills unspecified
annotations via wp_parse_args( $args['meta']['annotations'], static::$default_annotations ),
with no normalization to false. The property is documented bool|null, where null
("unspecified") is meaningfully distinct from an explicit false. assertEquals() hid the
mismatch because null == false. The strict assertion surfaces it directly:

     'annotations' => Array &1 (
         'readonly' => true
         'destructive' => false
-        'idempotent' => false
+        'idempotent' => null
     )

The expected value is corrected to null to match the documented and actual behaviour. This is
the one change here that is not a mechanical conversion.

sitemaps/wpSitemapsRenderer.php — DOMXPath::evaluate() returns a float for count().
Both assertions compared against integer 0. Proven by mutation: reverting to 0 fails with
Failed asserting that 0.0 is identical to 0.

Four string-vs-integer round trips, each cast on the expected side and proven by mutation:

  • admin/includesPost.php — WP_Post::$post_author is populated raw from the database and is documented @var string. Removing the cast fails with Failed asserting that '3' is identical to 3.
  • admin/wpCommentsListTable.php — WP_Comment::$comment_ID is a numeric string while the comment factory returns an integer. Fails with Failed asserting that '6' is identical to 6.
  • feed/atom.php — the enclosure length is read out of parsed XML as a string, while the fixture declares it as integer 318465. The sibling href and type assertions on the same lines already used assertSame(). Fails with Failed asserting that '318465' is identical to 318465.
  • http/base.php — the Content-Length response header is a string. See the note under Testing about how this one was verified.

ajax/wpAjaxHeartbeat.php needed no cast. wp_check_post_lock() assigns
$user = isset( $lock[1] ) ? (int) $lock[1] : (int) get_post_meta( ... ) and returns that, so
both sides are already integers.

Converted directly

db/charset.php (mb_convert_encoding() returns a string on both sides),
ajax/wpCustomizeManager.php (the sibling assertions on post_date in the same file already
use assertSame() against the same $future_date string),
formatting/wpTexturize.php, block-supports/layout.php (two strings extracted from the class
list), dependencies/scripts.php (the identical value is already asserted with assertSame()
seven lines above), l10n/wpTranslationsConvert.php, blocks/wpBlockMetadataRegistry.php,
block-templates/WpBlockTemplatesRegistry.php (unregister() returns the stored instance, so
identity holds), theme/wpThemeJson.php (2), and html-api/ (4 — plain arrays and strings
round-tripped through json_decode( ..., true )).

In admin/includes/misc/WpRefreshHeartbeatNonces_Test.php the two assertNotEquals() calls
convert directly: wp_create_nonce() returns a string on both sides, and the two
assertNotFalse( wp_verify_nonce( ... ) ) assertions immediately below already pin down the
positive case, so the negative assertion is not carrying the weight alone.

Left as assertEquals(), no changes

  • formatting/mapDeep.php (4) and formatting/stripslashesDeep.php (1) — each compares a freshly built (object) literal against the object the function returns. Different instances by construction.
  • bookmark/getBookmark.php (5) — compares a bookmark against the copy read back from the object cache. The file already documents the reason inline: the cached object "will have the same property values but will be a different object than the expected object".
  • abilities-api/ (3) — new WP_Ability( ... ) compared against the instance the registry built and stored.
  • admin/includesPost.php (2) — compares clone $post against $post to prove get_sample_permalink() does not modify the post object. Comparing a clone by value is the entire point of the test.
  • db/dbDelta.php (1) — a (object) literal against a $wpdb->get_row() result.
  • compat/clamp.php (1) — DateTimeImmutable instances built separately in the data provider.
  • functions/maybeSerialize.php (1) — already branches on is_object() and selects assertEquals() or assertSame() accordingly; correct as written.

Testing

This scope spans many directories rather than one group, so each changed file was run on its
own, single-site and multisite. All pass. Representative counts:

npm run test:php -- tests/phpunit/tests/dependencies/scripts.php
# OK (229 tests, 584 assertions)

npm run test:php -- tests/phpunit/tests/formatting/wpTexturize.php
# OK (357 tests, 441 assertions)

npm run test:php -- tests/phpunit/tests/theme/wpThemeJson.php
# OK (238 tests, 440 assertions)

npm run test:php -- --group html-api
# OK (1728 tests, 6156 assertions, 1 pre-existing skip)

npm run test:php -- --group sitemaps
# OK (159 tests, 236 assertions)

npm run test:php -- --group ajax
# OK (190 tests, 1212 assertions, 1 pre-existing skip)

Each of the above was also run against tests/phpunit/multisite.xml with the same result; the
multisite ajax group is 203 tests / 913 assertions.

admin/includesPost.php reports six warnings. These are pre-existing and unrelated: stashing
this branch's changes and running the same file on clean trunk produces the identical
Tests: 51, Assertions: 115, Warnings: 6.

http/base.php is the base class for Tests_HTTP_curl and Tests_HTTP_streams, both
@group external-http, so it is excluded from the default suite. Rather than assume the header
type, it was probed with an uncast assertSame():

npm run test:php -- --group external-http --filter test_file_stream
# Failed asserting that '153204' is identical to 153204.

The cast was then applied and the same command re-run: OK (4 tests, 14 assertions).

PHPCS clean on all 19 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: Cross-checking each expected literal against the return-type contract it is asserting,
and confirming every cast by mutation. I reviewed the conversions and take responsibility for
the final code.

#77 @lancewillett
7 weeks ago

In 63934:

Tests: Use strict assertions across additional test directories.

Replace loose comparisons with strict assertions where the expected types are known. Cast expected database IDs and serialized lengths to strings, and use float expectations for XPath counts.

Correct the expected default idempotent ability annotation to null, matching the API's documented default. Preserve object-value comparisons where distinct instances are expected.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13756

Props haritpanchal.
See #64895.

​@lancewillett commented on ​PR #13756:


7 weeks ago
#78

Nice work, @haritpanchal

Landed in https://core.trac.wordpress.org/changeset/63934

#79 @lancewillett
7 weeks ago

We're getting close to finished! Thanks everyone for your contributions.

@r1k0, checking in on your term/ claim from comment:43. Are you still working on it? If you have a patch or draft PR, please link it here so we can help review and test. If your availability has changed, no problem—let us know so someone else can pick it up.

#80 @r1k0
7 weeks ago

Yes, still working on it. I will submit a PR by the end of today.

#81 @lancewillett
7 weeks ago

In 63935:

Tests: Use strict assertions for REST responses and theme previews.

Compare REST response status codes and theme-preview hook priorities with integer expectations. Check ability pagination headers against string expectations without casting the returned values.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/11707

Props shreyasikhar26.
See #64895.

#82 @lancewillett
7 weeks ago

In 63936:

Tests: Replace native assertions in PHPUnit test classes.

Use PHPUnit type assertions in test setup and helpers so checks remain active when native PHP assertions are disabled and report failures through PHPUnit.

Retain native assertions outside PHPUnit test classes and add messages describing their invariants.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13651

Props soean.
See #64895.

This ticket was mentioned in ​PR #13769 on ​WordPress/wordpress-develop by ​@r1k0.


7 weeks ago
#85

cache.php

Kept the assertEquals() assertions as is because it is comparing different object instances but with the identical value.

categoryExists.php

Interchanged the expected value and actual value to ensure we are testing the function category_exists().

Cast the _$c*_ to a string to match the output of the actual value, which returns a string after category_exists() which in turn calls term_exists() that casts the _term_id_ to a string.

getTerm.php

Kept the assertEquals() assertions as is because it is comparing different object instances but with the identical value.

getTermBy.php

Kept the assertEquals() assertions as is because it is comparing different object instances but with the identical value.

getTerms.php

Changed the _expected_ values to strings because the actual value returns a numeric string when count is passed to $args['fields'] while calling get_terms().

meta.php

Cast the _expected_ values (meta_id and term_id) to a string to match the type returned by has_term_meta() which gives back a string value from the database.

query.php

For the _assertEquals()_ in Tests_Term_Query::test_orderby_include_with_comma_seperated_list I kept the assertEquals() assertions as is because it is comparing different array of objects with the identical value.

Changed the _expected_ values to strings because the actual value returns a numeric string when count is passed to $args['fields'] while calling get_terms().

splitSharedTerm.php

Changed the _expected_ values to strings because the actual value returns a numeric string after calling get_post_meta().

termsExists.php

Changed the _expected_ values to strings because term_exists() intentionally casts the _term_id_ to a string.

wpInsertTerm.php

Changed the _expected_ value to a string because wp_count_terms() intentionally returns a string.

In _Tests_Term_WpInsertTerm::test_wp_insert_should_return_term_id_and_term_taxonomy_id_ I kept the assertEquals() assertions as is because it is comparing different object instances but with the identical value.

In the helper function I cast _$tt_id_ to a string because the actual value returns a string when it interacts with term_exist() in its contract.

wpSetObjectTerms.php

I left the assertion as is because I believe there might be a bug (or this is intentional).

wp_set_objects_terms() returns an array of term taxonomy ID the problem is that there is no documented type contract for the values in the returned array. We have two types:

  1. When the terms don't exist, wp_insert_term() creates the term and returns the term taxonomy ID as an int.
  2. When the term exists, term_exists() returns the term taxonomyID as a string.

wpUpdateTerm.php

Kept the assertEquals() assertions as is because it is comparing different object instances but with the identical value.

Trac ticket: #64895

Use of AI Tools

N/A

#86 @lancewillett
6 weeks ago

In 63944:

Tests: Use strict assertions in term tests.

Use strict comparisons for term IDs, taxonomy counts, and metadata, matching expected values to the types returned by the APIs. Correct the expected and actual argument order in category_exists() tests.

Preserve object-value comparisons and document why they remain intentional.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13769

Props r1k0, mukesh27.
See #64895.

#88 @lancewillett
6 weeks ago

The last outstanding directory claim, term/, landed in [63944] via ​https://github.com/WordPress/wordpress-develop/pull/13769. All currently claimed directories are accounted for, and no open wordpress-develop PRs reference this ticket.

The remaining assertEquals() calls are not a target to eliminate indiscriminately: we'll retain object-value comparisons and other intentional loose comparisons for now. The link/ and pomo/ reviews are documented in comments 27 and 22.

Thanks to everyone who contributed patches, reviews, and testing! Leaving this ticket open while we check the Gutenberg follow-up requested in the original description, including what was already handled in earlier release cycles.

#89 @lancewillett
6 weeks ago

There is a concrete Gutenberg follow-up here, and volunteers are welcome to pick it up.

  1. Start with a small Gutenberg PR syncing four assertions already converted in [63934]:
  1. Complete a broader scan of Gutenberg's PHPUnit tests and submit focused PRs where strict comparisons protect the return-type contract. The initial scan found 154 assertEquals() calls across 21 files at the linked revision. This is an inventory, not a conversion target: inspect each assertion, preserve intentional object-value comparisons, and check existing PRs and code history before making changes.

There is useful precedent: ​Gutenberg #58502 updated Font Library assertions for the 6.5 cleanup, and ​#58476 synced theme.json tests from Core.

Please claim a file or small group here and link your Gutenberg PR back to this ticket. For the first PR, use [63934] as the starting point and verify the changes against Gutenberg's current implementation. Run the affected tests in single-site and multisite, including randomized order.

Keeping this ticket open for that follow-up. Thanks to everyone helping with patches, reviews, and testing!

Research assistance: OpenAI Codex (GPT-6), used to inspect code and history and identify the initial candidates.

Last edited 6 weeks ago by lancewillett (previous) (diff)

#90 @haritpanchal
6 weeks ago

Working on the Gutenberg follow-up, starting with the four assertions from [63934]: the layout
container hash, the template unregister check, and the two block-node path tests.

Gutenberg PR: ​https://github.com/WordPress/gutenberg/pull/83619

I checked the open Gutenberg pull requests first and none of them touch assertEquals() in the
PHPUnit tests, so there is no overlap to redo. The wider inventory on Gutenberg trunk today is
154 assertEquals() across 21 files, matching the count in comment 89; I will claim the rest in
smaller groups.

Last edited 6 weeks ago by haritpanchal (previous) (diff)

#91 @haritpanchal
6 weeks ago

Working on the style engine group.

3 assertEquals() in one file, phpunit/style-engine/class-wp-style-engine-css-rules-store-test.php, I checked the open Gutenberg pull requests first and none of them touch this file, so there is no overlap to redo.

Starting with a small group to keep the pull requests easy to review; I will pick up a larger
one next.

Gutenberg PR for the style engine group: ​https://github.com/WordPress/gutenberg/pull/83777

Last edited 6 weeks ago by haritpanchal (previous) (diff)

#92 @noruzzaman
6 weeks ago

Working on the override script tests follow-up in Gutenberg.

Replaced loose assertEquals() with type-strict assertSame() in phpunit/class-override-script-test.php.

Gutenberg PR: ​https://github.com/WordPress/gutenberg/pull/83782

#93 follow-up: @lancewillett
6 weeks ago

Status on trunk today ([64005]): 200 assertEquals() calls left in 60 files, down from 501 in 124 files on September 8. Every directory claimed so far has landed, so the rest is open.

Remaining by directory (calls / files):

  • term/: 34 / 7
  • link/: 29 / 1
  • top-level files in tests/phpunit/tests/: 18 / 8
  • rest-api/: 16 / 5
  • query/: 15 / 3
  • customize/: 14 / 3
  • pomo/: 10 / 2
  • option/: 9 / 6
  • multisite/: 8 / 2
  • bookmark/: 7 / 1
  • post/: 6 / 4
  • block-bindings/: 6 / 2
  • formatting/: 5 / 2
  • abilities-api/: 4 / 2
  • user/: 3 / 2
  • one or two each in admin/, comment/, compat/, db/, functions/ and xmlrpc/
  • tests/phpunit/includes/: 8 / 4

Not every one should become assertSame(). link/getAdjacentPost.php, the largest single file, compares WP_Post objects, where assertEquals() is the right call. For those, a short note in the test saying the loose comparison is deliberate counts as done.

To claim a directory, comment here with its name. One directory per PR, and run it before and after: npm run test:php -- --test-suffix .php tests/phpunit/tests/<dir>.

Thanks @haritpanchal and @noruzzaman for picking up the Gutenberg follow-up.

Edited: added --test-suffix .php. Without it, PHPUnit only loads files ending in Test.php when given a directory, so 68 of the 72 directories on trunk run zero tests.

Last edited 6 weeks ago by lancewillett (previous) (diff)

This ticket was mentioned in ​PR #13832 on ​WordPress/wordpress-develop by ​@noruzzaman.


6 weeks ago
#94

What

Reviewed the bookmark/ directory (tests/phpunit/tests/bookmark/) for ticket #64895.

In tests/phpunit/tests/bookmark/getBookmark.php, there are 5 calls to assertEquals():

  • Line 146: Comparing $bookmark with $actual_cache returned from wp_cache_get().
  • Line 235: Comparing $expected object with $actual_bookmark returned from get_bookmark().
  • Line 242: Comparing self::$bookmark with $actual_cache returned from wp_cache_get().
  • Line 293: Comparing $expected object with $actual_bookmark returned from database row.
  • Line 300: Comparing self::$bookmark with $actual_cache returned from wp_cache_get().

All 5 comparisons intentionally compare objects by value rather than reference identity:

  1. WP_Object_Cache::get() explicitly clones objects upon retrieval (return clone $this->cache[ $group ][ $key ];), meaning $actual_cache and cached bookmark objects are distinct instances from the originals.
  2. In database fetch paths, $actual_bookmark is a distinct stdClass object instance created from $wpdb->get_row().
  3. Array return paths already use assertSameSets() (lines 237, 295).

Per the maintainer guidance on ticket #64895, these loose comparisons are deliberate. Added the canonical // Keep assertEquals() because the objects are intentionally compared by value. comment above each assertEquals() call, consistent with existing patterns across tests/phpunit/tests/term/cache.php, tests/phpunit/tests/term/wpInsertTerm.php, and tests/phpunit/tests/customize/nav-menu-setting.php.

The remaining file in the directory, getBookmarks.php, has no assertEquals() calls.

100% test-only change; zero production code modified.

Testing

npm run test:php -- --test-suffix .php tests/phpunit/tests/bookmark
# 52 tests, 182 assertions (100% pass)

npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/bookmark
# 52 tests, 182 assertions (100% pass)

composer run lint tests/phpunit/tests/bookmark/getBookmark.php
# 1 file, 0 errors, 0 warnings

#95 @lancewillett
6 weeks ago

In 64015:

Tests: Document value comparisons in bookmark tests.

Explain why five assertEquals() calls intentionally compare bookmark objects by value. Cache retrieval and database queries return separate object instances, so identity comparisons would be inappropriate.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13832

Props noruzzaman.
See #64895.

This ticket was mentioned in ​PR #13902 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#97

Description

Reviewed tests/phpunit/tests/block-bindings/ for ticket #64895.

There are 6 calls to assertEquals() across 2 files:

  • tests/phpunit/tests/block-bindings/register.php:
    • Line 83: Comparing $expected array of WP_Block_Bindings_Source instances with $registered.
    • Line 100: Comparing expected new WP_Block_Bindings_Source(...) with $result from unregister_block_bindings_source().
  • tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php:
    • Line 192: Comparing expected new WP_Block_Bindings_Source(...) with $result from WP_Block_Bindings_Registry::register().
    • Line 238: Comparing expected new WP_Block_Bindings_Source(...) with $result from WP_Block_Bindings_Registry::unregister().
    • Line 277: Comparing $expected array of WP_Block_Bindings_Source instances with $registered.
    • Line 322: Comparing expected new WP_Block_Bindings_Source(...) with $result from WP_Block_Bindings_Registry::get_registered().

All 6 assertions intentionally compare WP_Block_Bindings_Source objects by value. Because test methods instantiate new expected WP_Block_Bindings_Source objects rather than keeping reference identity with internally stored instances, strict identity comparison (assertSame()) is not appropriate here.

In accordance with maintainer guidance on Trac #64895, these loose comparisons are retained 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/block-bindings
npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/block-bindings
composer run lint tests/phpunit/tests/block-bindings

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Identifying intentional object value comparisons and drafting documentation comments. Implementation and test verification were reviewed and executed locally.

This ticket was mentioned in ​PR #13903 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#98

Description

Reviewed tests/phpunit/tests/abilities-api/ for ticket #64895.

There are 4 calls to assertEquals() across 2 files:

  • tests/phpunit/tests/abilities-api/wpAbilitiesRegistry.php:
    • Line 519: Comparing new WP_Ability(...) with $result from WP_Abilities_Registry::register().
  • tests/phpunit/tests/abilities-api/wpRegisterAbility.php:
    • Line 523: Comparing new WP_Ability(...) with $result from wp_unregister_ability().
    • Line 586: Comparing new WP_Ability(...) with $result from wp_get_ability().
    • Line 705: Comparing $expected array of WP_Ability instances with $result from wp_get_abilities().

All 4 calls intentionally compare WP_Ability objects by value. Because test methods instantiate distinct expected object instances, strict identity assertions (assertSame()) would fail.

Per maintainer guidance on Trac #64895, 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/abilities-api
npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/abilities-api
composer run lint tests/phpunit/tests/abilities-api

Use of AI Tools

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

​@lancewillett commented on ​PR #13902:


6 weeks ago
#99

Optional follow-up, new PR: assert that unregistering also removes the source from the registry. This existing gap needn’t block these comment-only changes.

#100 @lancewillett
6 weeks ago

In 64031:

Tests: Document object-value comparisons in block bindings tests.

Explain why six assertions retain assertEquals(): the expected block binding sources are separate instances whose properties are compared by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13902

Props huzaifaalmesbah.
See #64895.

#102 @lancewillett
6 weeks ago

In 64032:

Tests: Document object-value comparisons in abilities API tests.

Explain why four assertions retain assertEquals(): the expected abilities are separate instances whose properties are compared by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13903

Props huzaifaalmesbah.
See #64895.

This ticket was mentioned in ​PR #13932 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#104

Description

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

There are 10 calls to assertEquals() across 2 files:

  • tests/phpunit/tests/pomo/mo.php:
    • Line 61: Comparing $plural_entry with $mo->entries[ $plural_entry->key() ].
    • Line 71: Comparing $single_entry with $mo->entries[ $single_entry->key() ].
    • Line 141: Comparing $entry with $again->entries[ $entry->key() ] after exporting and importing an MO file.
  • tests/phpunit/tests/pomo/po.php:
    • Lines 285, 295, 303, 313, 324, 327: Comparing expected Translation_Entry objects with entries parsed from PO files.
    • Line 388: Comparing $po->entries array of Translation_Entry objects with $entries.

All 10 calls intentionally compare Translation_Entry object instances by value across separate instantiation or file-import paths. Identity comparison (assertSame()) is inappropriate because distinct object instances are created during parsing.

In accordance with maintainer guidance on Trac #64895 (comments 88 & 93), these deliberate 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/pomo
npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/pomo
composer run lint tests/phpunit/tests/pomo

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.

This ticket was mentioned in ​PR #13933 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#105

Description

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

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

  • tests/phpunit/tests/user/capabilities.php:
    • Line 2137: Comparing new WP_Role(...) with $role returned from $wp_roles->get_role().
  • tests/phpunit/tests/user/updateUserCaches.php:
    • Line 15: Comparing raw database row $raw_userdata (from $wpdb->get_row()) with cached object returned from wp_cache_get( $u, 'users' ).
    • Line 69: Comparing raw database row $raw_userdata with cached object returned from wp_cache_get( $u, 'users' ).

All 3 calls intentionally compare object instances by value:

  1. WP_Role constructor creates a fresh object instance that differs in object identity from the registered instance stored in $wp_roles.
  2. Cache retrieval returns distinct object instances from the original database row instance retrieved via $wpdb->get_row().

In accordance with maintainer guidance on Trac #64895, 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/user/capabilities.php tests/phpunit/tests/user/updateUserCaches.php
composer run lint tests/phpunit/tests/user/capabilities.php tests/phpunit/tests/user/updateUserCaches.php

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.

This ticket was mentioned in ​PR #13934 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#106

Description

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

There are 5 calls to assertEquals() across 2 files:

  • tests/phpunit/tests/formatting/mapDeep.php:
    • Line 80: Comparing expected (object) with mapped object returned from map_deep().
    • Line 96: Comparing expected (object) with mapped object containing an array property returned from map_deep().
    • Line 116: Comparing expected (object) with mapped nested object returned from map_deep().
    • Line 144: Comparing expected (object) with mapped object having properties passed by reference returned from map_deep().
  • tests/phpunit/tests/formatting/stripslashesDeep.php:
    • Line 48: Comparing expected $obj_new (stdClass) with stripped object returned from stripslashes_deep().

All 5 calls intentionally compare object instances by value:

  1. map_deep() and stripslashes_deep() operate recursively on object structures. When comparing the transformed output with an expected object created in the test, they represent separate stdClass instances.
  2. Identity assertions (assertSame()) fail on distinct object instances.

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/formatting/mapDeep.php tests/phpunit/tests/formatting/stripslashesDeep.php
composer run lint tests/phpunit/tests/formatting/mapDeep.php tests/phpunit/tests/formatting/stripslashesDeep.php

Use of AI Tools

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

This ticket was mentioned in ​PR #13935 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#107

Description

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

There are 29 calls to assertEquals() in tests/phpunit/tests/link/getAdjacentPost.php:

  • test_get_adjacent_post(): 13 calls comparing WP_Post objects or arrays of WP_Post objects returned from get_adjacent_post().
  • test_get_adjacent_post_exclude_self_term(): 8 calls comparing WP_Post objects returned from get_adjacent_post().
  • test_get_adjacent_post_caching(): 8 calls comparing WP_Post objects returned from get_adjacent_post().

All 29 calls intentionally compare WP_Post instances by value:

  1. get_adjacent_post() queries the database and instantiates fresh WP_Post objects, which are distinct instances from the fixture references in the test.
  2. assertSame() strictly checks object identity (===), which fails when comparing distinct WP_Post instances representing the same post.

As noted specifically by committer @lancewillett in Trac #64895 (comment:93):

"link/getAdjacentPost.php, the largest single file, compares WP_Post objects, where assertEquals() is the right call. For those, a short note in the test saying the loose comparison is deliberate counts as done."

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/link/getAdjacentPost.php
composer run lint tests/phpunit/tests/link/getAdjacentPost.php

Use of AI Tools

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

#108 @lancewillett
6 weeks ago

In 64064:

Tests: Document object value comparisons in POMO tests.

Explain why MO and PO tests retain assertEquals() for Translation_Entry objects. Expected entries and imported entries are distinct instances whose values should match.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13932

Props huzaifaalmesbah.
See #64895.

This ticket was mentioned in ​PR #13936 on ​WordPress/wordpress-develop by ​@noruzzaman.


6 weeks ago
#110

Description

Reviewed tests/phpunit/tests/rest-api/ for ticket #64895.

There were 16 calls to assertEquals() across 5 files:

Strict Assertion Replacements (assertSame()):

  1. tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php:
    • Line 438: Converted assertEquals( 200, $response->get_status() ) to assertSame().
    • Line 469: Converted assertEquals( 404, $response->get_status() ) to assertSame().
  2. tests/phpunit/tests/rest-api/wpRestAbilitiesV1RunController.php:
    • Line 432: Converted status code / data comparison assertEquals( 8, $response->get_data() ) to assertSame().
    • Line 454: Converted assertEquals( self::$user_id, $data['id'] ) to assertSame().
    • Line 678: Converted status code comparison assertEquals( 200, $response->get_status() ) to assertSame().
    • Line 792: Converted array comparison assertEquals( array( 1, 2, 3 ), $data['array'] ) to assertSame().
    • Line 1300: Converted assertEquals( $inputs, $data['echo'] ) to assertSame().
    • Lines 1349–1351: Converted string assertions for $input['utf8'], $input['emoji'], and $input['html'] to assertSame().

Object Value Comparisons Documented:

  1. tests/phpunit/tests/rest-api/rest-block-renderer-controller.php:
    • Line 383: Comparing json_decode() stdClass instances returned by the block type renderer against $data['rendered'].
  2. tests/phpunit/tests/rest-api/rest-users-controller.php:
    • Lines 1178–1179: Comparing $data['capabilities'] and $data['extra_capabilities'] against new stdClass().
    • Lines 3358–3359: Comparing (object) $user->allcaps and (object) $user->caps against $data['capabilities'] and $data['extra_capabilities'].
  3. tests/phpunit/tests/rest-api/wpRestTemplatesController.php:
    • Line 1184: Comparing new stdClass() with $data when a fallback template is not found.

In accordance with maintainer guidance on Trac #64895, scalar/integer/array assertions are converted to assertSame(), and intentional object-value comparisons are preserved and documented with:
// Keep assertEquals() because the objects are intentionally compared by value.

Testing Instructions

npm run test:php -- tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php tests/phpunit/tests/rest-api/wpRestAbilitiesV1RunController.php tests/phpunit/tests/rest-api/rest-block-renderer-controller.php tests/phpunit/tests/rest-api/wpRestTemplatesController.php
npm run test:php -- --filter WP_Test_REST_Users_Controller
npm run test:php -- -c tests/phpunit/multisite.xml --filter WP_Test_REST_Users_Controller
composer run lint tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php tests/phpunit/tests/rest-api/wpRestAbilitiesV1RunController.php tests/phpunit/tests/rest-api/rest-block-renderer-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/wpRestTemplatesController.php

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.

This ticket was mentioned in ​PR #13937 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#111

In #13933 (reviewed by @lancewillett), we documented intentional loose comparisons in the user/ test suite. During review, core committer @lancewillett highlighted an existing coverage gap:

"One existing coverage gap surfaced during review: both object-comparison cache tests still pass with their explicit update_user_caches() call removed. Could you open a follow-up PR that clears the users cache entry after setup, then verifies each test fails without that call? This needn’t hold up #13933."

What this PR does

When a user is created via self::factory()->user->create(), the users cache bucket is automatically populated during user creation. Consequently, test_should_store_entire_database_row_in_users_bucket() and test_should_store_raw_data_in_users_bucket_when_passed_a_wp_user_object() would previously pass even if the explicit update_user_caches() call was removed.

This PR adds wp_cache_delete( , 'users' ) after test fixture setup in both methods, ensuring that:

  1. The users cache is cleared prior to calling update_user_caches().
  2. The tests genuinely verify that update_user_caches() repopulates the users cache bucket.
  3. If update_user_caches() is removed or fails, both tests fail as expected (false does not match expected type "object").

Scope

  • 100% test-only change; zero production code modified.
  • Verified locally that both tests fail when update_user_caches() is removed, and pass when present.

Testing Instructions

# Run user test suite locally
npm run test:php -- --test-suffix .php tests/phpunit/tests/user/updateUserCaches.php

# Multisite suite
npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/user/updateUserCaches.php

# Code style check
composer run lint tests/phpunit/tests/user/updateUserCaches.php

Follow-up to: ​https://github.com/WordPress/wordpress-develop/pull/13933
Trac tickets: https://core.trac.wordpress.org/ticket/64895, https://core.trac.wordpress.org/ticket/24635

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Analyzing test fixture cache state and drafting PR description. Implementation, test failure verification, and code review were verified locally.

​@huzaifaalmesbah commented on ​PR #13933:


6 weeks ago
#112

Follow-up PR opened in #13937: verified both tests fail with update_user_caches() removed and pass with it restored after clearing the users cache entry. Thank you for the review!

#113 @lancewillett
6 weeks ago

In 64065:

Tests: Document object value comparisons in user tests.

Explain why role and user cache tests retain assertEquals(). These checks compare object values rather than the identity of separately created or cached objects.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13933

Props huzaifaalmesbah.
See #64895.

#115 @lancewillett
6 weeks ago

In 64066:

Tests: Document object value comparisons in formatting tests.

Explain why map_deep() and stripslashes_deep() tests retain assertEquals() when comparing transformed objects with separately constructed expected objects.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13934

Props huzaifaalmesbah.
See #64895.

This ticket was mentioned in ​PR #13939 on ​WordPress/wordpress-develop by ​@noruzzaman.


6 weeks ago
#117

Description

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

There are 6 calls to assertEquals() across 4 files:

  • tests/phpunit/tests/post/getPageByPath.php:
    • Line 41: Comparing $page (WP_Post) with object returned from get_page_by_path( 'some-page' ).
    • Line 44: Comparing $other_att (WP_Post) with object returned from get_page_by_path( 'some-other-page' ).
  • tests/phpunit/tests/post/meta.php:
    • Line 174: Comparing $mobj (stdClass) with database row object returned from get_post_meta_by_id( $mid ).
    • Line 181: Comparing $mobj (stdClass) with database row object returned from get_post_meta_by_id( $mid ).
  • tests/phpunit/tests/post/types.php:
    • Line 295: Comparing $before labels object (stdClass) with $after labels object after calling get_post_type_labels().
  • tests/phpunit/tests/post/wpCountAttachments.php:
    • Line 31: Comparing $expected object with cached object returned from wp_cache_get( $cache_key, 'counts' ).

All 6 calls intentionally compare object instances by value:

  1. get_page_by_path() queries the database and instantiates a WP_Post object, which is a separate instance from fixture references in the test.
  2. get_post_meta_by_id() constructs a database row object, distinct from the manually constructed $mobj fixture.
  3. get_post_type_labels() casts the labels array to a fresh (object), producing a distinct instance from $before.
  4. WP_Object_Cache::get() intentionally clones objects upon cache retrieval, returning a distinct instance in memory from $expected.

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 -- tests/phpunit/tests/post/getPageByPath.php tests/phpunit/tests/post/meta.php tests/phpunit/tests/post/types.php tests/phpunit/tests/post/wpCountAttachments.php
npm run test:php -- -c tests/phpunit/multisite.xml tests/phpunit/tests/post/getPageByPath.php tests/phpunit/tests/post/meta.php tests/phpunit/tests/post/types.php tests/phpunit/tests/post/wpCountAttachments.php
composer run lint tests/phpunit/tests/post/getPageByPath.php tests/phpunit/tests/post/meta.php tests/phpunit/tests/post/types.php tests/phpunit/tests/post/wpCountAttachments.php

This ticket was mentioned in ​PR #13940 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


6 weeks ago
#118

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

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.

#119 @lancewillett
6 weeks ago

In 64067:

Tests: Document object value comparisons in adjacent post tests.

Explain why adjacent and boundary post tests retain assertEquals() when comparing WP_Post objects and arrays of posts by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13935

Props huzaifaalmesbah.
See #64895.

​@noruzzaman commented on ​PR #13936:


6 weeks ago
#121

Updated! The test/calculator ability defines an output_schema of type number, which rest_sanitize_value_from_schema() casts to a float (8.0). I've updated the assertion to $this->assertSame( 8.0, $response->get_data() );.

All 47 tests and 217 assertions pass in both single-site and multisite runs.

#122 @lancewillett
6 weeks ago

In 64068:

Tests: Clear cached users before testing user cache updates.

Remove the users cache entry after fixture setup so the tests verify that update_user_caches() populates it. Previously, both object-comparison tests passed even without the explicit cache update.

Follow-up to [64065].

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13937

Props huzaifaalmesbah.
See #64895, #24635.

#124 @lancewillett
6 weeks ago

In 64069:

Tests: Document object value comparisons in query tests.

Explain why post data and queried term tests retain assertEquals() when comparing WP_User and WP_Term objects by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13940

Props huzaifaalmesbah.
See #64895.

#126 @lancewillett
6 weeks ago

In 64070:

Tests: Use strict assertions in REST API tests.

Use assertSame() for status codes, numeric results, arrays, and strings in the Abilities API tests. Expect the calculator result as a float because its number inputs are normalized to floats.

Document why comparisons of separate objects retain assertEquals() in the block renderer, users, and templates tests.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13936

Props noruzzaman.
See #64895.

#128 @lancewillett
6 weeks ago

In 64071:

Tests: Document object value comparisons in post tests.

Explain why post lookup, metadata, post type label, and attachment count tests retain assertEquals() when comparing separately constructed or cached objects by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13939

Props noruzzaman.
See #64895.

This ticket was mentioned in ​PR #13945 on ​WordPress/wordpress-develop by ​@noruzzaman.


6 weeks ago
#130

Description

This pull request reviews all assertEquals() assertions in tests/phpunit/tests/option/ for Trac ticket #64895.

There are 8 calls to assertEquals() across 6 files under tests/phpunit/tests/option/. All comparisons are intentional value comparisons:

  1. tests/phpunit/tests/option/option.php (Line 160):
    • Compares expected stdClass with object returned from get_option( $key ). In WordPress, option objects are serialized on save and unserialized on retrieval, producing a distinct object instance. Added explanatory comment.
  1. tests/phpunit/tests/option/sanitizeOption.php (Line 161):
    • Compares expected permalink structure sanitize result ($expected) with $actual. On single-site installations get_option( 'permalink_structure' ) returns false, while on multisite installations it returns '' (empty string). Retained assertEquals() and added an explanatory comment.
  1. tests/phpunit/tests/option/siteOption.php (Line 203):
    • Compares expected stdClass with object returned from get_site_option( $key ). Added explanatory comment.
  1. tests/phpunit/tests/option/siteTransient.php (Lines 54, 95, 125):
    • Line 54: Compares expected stdClass with transient object returned from get_site_transient( $key ).
    • Lines 95, 125: Compares expected (object) array(...) with database row object returned by $wpdb->get_row(). Added explanatory comments.
  1. tests/phpunit/tests/option/transient.php (Line 54):
    • Compares expected stdClass with transient object returned from get_transient( $key ). Added explanatory comment.
  1. tests/phpunit/tests/option/wpPrimeOptionCaches.php (Line 271):
    • Already documented with an existing inline comment explaining object shape comparison vs non-object assertSame(). No changes needed.

Testing Instructions

Run option unit tests in both single-site and multisite configurations:

npm run test:php -- --test-suffix .php tests/phpunit/tests/option/
npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/option/

All 417 single-site tests (1,073 assertions) and 452 multisite tests (1,187 assertions) pass cleanly.

---

This ticket was mentioned in ​PR #13946 on ​WordPress/wordpress-develop by ​@noruzzaman.


6 weeks ago
#131

Description

This pull request audits and updates assertions in tests/phpunit/tests/multisite/ for Trac ticket #64895.

Changes Made:

  1. Strict Assertion Replacement (assertNotSame()):
    • tests/phpunit/tests/multisite/msFilesRewriting.php (Line 37):
      • Converted $this->assertNotEquals( $info, $info2 ); to $this->assertNotSame( $info, $info2 );. Both variables are arrays returned by wp_upload_dir(), so strict inequality assertion is appropriate.
  1. Documentation of Intentional Value Comparisons:
    • tests/phpunit/tests/multisite/network.php (Lines 242, 273):
      • Added inline comments explaining that assertEquals() is retained because get_blog_count() may return a numeric string from the database/transient (e.g. '1' vs 1, or '3' vs 3).
    • tests/phpunit/tests/multisite/site.php (Lines 152, 163, 164, 441, 602, 613):
      • Lines 152, 163, 164, 441: Added comments explaining that cached site objects returned from wp_cache_get() are intentionally compared by value with expected WP_Site instances.
      • Lines 602, 613: Added comments explaining that remote post objects retrieved via get_blog_post() and get_post() are separate WP_Post instances intentionally compared by value.

Testing Instructions

Run multisite PHPUnit test suite:

npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/multisite/
npm run test:php -- -c tests/phpunit/multisite.xml --group ms-files

All 675 multisite tests (1,496 assertions) pass cleanly.

---

This ticket was mentioned in ​PR #13947 on ​WordPress/wordpress-develop by ​@noruzzaman.


6 weeks ago
#132

Description

Reviewed tests/phpunit/tests/cron.php for ticket #64895 ("Tests: Reduce usage of assertEquals for 7.2").

There are 7 calls to assertEquals() in tests/phpunit/tests/cron.php:

  • test_get_scheduled_event_preflight(): 1 call comparing expected scheduled event object with the object returned from wp_get_scheduled_event() via pre_get_scheduled_event filter.
  • test_get_scheduled_event_singles(): 3 calls comparing expected one-off event objects with objects returned from wp_get_scheduled_event().
  • test_get_scheduled_event_recurring(): 3 calls comparing expected recurring event objects with objects returned from wp_get_scheduled_event().

All 7 assertions compare distinct stdClass event object instances by value:

  1. wp_get_scheduled_event() constructs fresh (object) array(...) representations of scheduled cron jobs, which are distinct instances from the expected fixtures instantiated in the test methods.
  2. assertSame() strictly checks object identity (===), which fails when comparing distinct stdClass instances representing the same scheduled event.

These intentional object value comparisons are preserved and documented with:
// Keep assertEquals() because the objects are intentionally compared by value.

All other assertions in tests/phpunit/tests/cron.php and tests/phpunit/tests/cron/ already utilize strict assertions (assertSame(), assertTrue(), assertFalse(), assertWPError(), assertNotWPError(), assertCount(), assertIsArray()).

Testing Instructions

Run the cron PHPUnit test suite locally:

npm run test:php -- tests/phpunit/tests/cron.php
npm run test:php -- --group cron
npm run test:php -- -c tests/phpunit/multisite.xml tests/phpunit/tests/cron.php
composer run lint tests/phpunit/tests/cron.php

All 52 single-site tests (193 assertions), 89 cron group tests (279 assertions), and 52 multisite tests pass 100%.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Inspecting assertion calls, drafting explanatory comments, and formatting the PR description. Implementation, verification, and test execution were reviewed locally.

#133 @lancewillett
5 weeks ago

In 64078:

Tests: Document value comparisons in option tests.

Explain why option and transient tests retain assertEquals() for object values and the differing empty permalink defaults on single-site and multisite installations.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13945

Props noruzzaman.
See #64895.

#135 @lancewillett
5 weeks ago

In 64079:

Tests: Clarify comparisons in multisite tests.

Use assertNotSame() when comparing upload directory arrays after switching sites. Document why numeric counts and object comparisons retain assertEquals().

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13946

Props noruzzaman.
See #64895.

#137 @lancewillett
5 weeks ago

In 64080:

Tests: Document value comparisons in cron tests.

Explain why scheduled event tests retain assertEquals() when comparing separate event objects by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13947

Props noruzzaman.
See #64895.

This ticket was mentioned in ​PR #13965 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#139

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

What?

Reviewed tests/phpunit/includes/ for ticket #64895 and documented the remaining intentional assertEquals() calls.

There are 8 calls across 4 files:

  • testcase-rest-post-type-controller.php
  • testcase-canonical.php
  • abstract-testcase.php
  • utils.php

No assertion method names were changed. Each leftover assertEquals() now has a short comment explaining why the loose comparison is deliberate.

Why?

assertEquals() does not check types. Ticket #64895 asks contributors to convert to assertSame() when the type is part of the contract, and to keep assertEquals() when the loose comparison is intentional — with a note in the test.

These includes helpers fall in the second group:

  • REST author compares a DB string (WP_Post::$post_author) with a REST integer
  • Canonical query vars mix int/string scalars from rewrite/$_GET
  • assertEqualSets*() are the loose counterparts to assertSameSets*()
  • assertDiscardWhitespace() accepts mixed types
  • gen_tests_array() is unused scaffolding

Documenting them matches the current leftover work on this ticket (same approach as recent option/cron/multisite PRs).

How?

Added Keep assertEquals() ... comments next to each remaining call:

  • REST post type controller: string vs int author mismatch
  • Canonical helper: mixed query-var scalar types
  • assertDiscardWhitespace(), assertEqualSets(), assertEqualSetsWithIndex(): intentional loose helper behavior
  • gen_tests_array(): scaffolding-only generator

No production code and no assertion conversions.

Testing Instructions

These are comment-only test helper changes. Confirm the related suites still pass:

npm run test:php -- --group rest-api
npm run test:php -- --group canonical
npm run test:php -- --test-suffix .php tests/phpunit/includes

Optional multisite:

npm run test:php -- -c tests/phpunit/multisite.xml --group rest-api
npm run test:php -- -c tests/phpunit/multisite.xml --group canonical

Expected: all green; no assertion count changes beyond existing suite noise.

Use of AI Tools

  • Cursor

#140 @lancewillett
5 weeks ago

In 64084:

Tests: Explain intentional loose comparisons in test helpers.

Document why test helpers retain assertEquals() for mixed scalar types, whitespace normalization, loose set comparisons, and generated test scaffolding. No assertion behavior changes.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13965

Props shailu25.
See #64895.

This ticket was mentioned in ​PR #13993 on ​WordPress/wordpress-develop by ​@noruzzaman.


5 weeks ago
#142

Description

This pull request reviews all assertEquals() assertions in tests/phpunit/tests/admin/ for Trac ticket #64895.

There are 2 calls to assertEquals() in tests/phpunit/tests/admin/includesPost.php:

  • Lines 970 & 978 in test_get_sample_permalink_filter(): Compares $post_original = clone $post with $post by value before and after the filter and get_sample_permalink() call to verify that the original object state is unmodified. Added explanatory inline comments.

Testing Instructions

Run admin unit tests in both single-site and multisite configurations:

npm run test:php -- --test-suffix .php tests/phpunit/tests/admin/includesPost.php
npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/admin/includesPost.php

All 51 single-site tests (115 assertions) and 51 multisite tests (115 assertions) pass cleanly.


This ticket was mentioned in ​PR #13994 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#143

Description

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

There is 1 call to assertEquals() in this directory:

  • tests/phpunit/tests/compat/clamp.php
    • Line 197: Comparing a DateTimeImmutable expected value from the data provider with the object returned from clamp( $value, $min, $max ).

The data provider builds fresh DateTimeImmutable instances for $expected, $value, $min, and $max. clamp() returns one of those bound/value objects (or an equivalent value within the range), so the comparison is by value across separately constructed instances. assertSame() would require identical object identity and is not appropriate here.

Per maintainer guidance on Trac #64895 (comments 88 & 93), this intentional loose comparison is preserved and documented with:

// Keep assertEquals() because the objects are intentionally compared by value.

No other files under compat/ contain assertEquals().

Testing Instructions

npm run test:php -- --test-suffix .php tests/phpunit/tests/compat

Use of AI Tools

AI assistance: Yes
Tool(s): Cursor
Used for: Locating remaining undocumented assertEquals() calls for #64895 and drafting the inline comment / PR description. Changes were reviewed before opening the PR.

This ticket was mentioned in ​PR #13995 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#144

Description

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

There is 1 call to assertEquals() in this directory:

  • tests/phpunit/tests/db/dbDelta.php
    • assertTableRowHasValue(): Comparing a freshly built (object) array( $column => $value ) expected literal with the stdClass row returned from $wpdb->get_row().

$wpdb->get_row() always constructs a new object from the database result. The expected value is a separate stdClass instance built in the helper, so the comparison is by value. assertSame() would fail because the instances are not identical.

Per maintainer guidance on Trac #64895 (comments 88 & 93), this intentional loose comparison is preserved and documented with:

// Keep assertEquals() because the objects are intentionally compared by value.

No other files under db/ contain assertEquals().

Testing Instructions

npm run test:php -- --test-suffix .php tests/phpunit/tests/db

Use of AI Tools

AI assistance: Yes
Tool(s): Cursor
Used for: Locating remaining undocumented assertEquals() calls for #64895 and drafting the inline comment / PR description. Changes were reviewed before opening the PR.

​@shailu25 commented on ​PR #13994:


5 weeks ago
#145

Closing for now — will keep the work on the branch only and open a PR after claiming on the Trac ticket.

​@shailu25 commented on ​PR #13995:


5 weeks ago
#146

Closing for now — will keep the work on the branch only and open a PR after claiming on the Trac ticket.

This ticket was mentioned in ​PR #13996 on ​WordPress/wordpress-develop by ​@noruzzaman.


5 weeks ago
#147

Description

Follow-up to #64895. In tests/phpunit/tests/term/:

  • In getTermBy.php: Added explanatory comment documenting why assertEquals() is retained in test_get_term_by_id() for comparing WP_Term objects by value.
  • In wpSetObjectTerms.php: Added explanatory comment in test_change_object_terms_by_name() documenting why assertEquals() is retained when comparing term taxonomy IDs returned by wp_set_object_terms(), which may return numeric strings or integers.

This ticket was mentioned in ​PR #13997 on ​WordPress/wordpress-develop by ​@noruzzaman.


5 weeks ago
#148

Description

Follow-up to #64895. In tests/phpunit/tests/compat/clamp.php:

  • Added an explanatory comment to test_clamp_with_datetime() documenting why assertEquals() is retained when comparing DateTimeImmutable objects by value.

This ticket was mentioned in ​PR #13998 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#149

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

What?

Documents the remaining intentional assertEquals() call in tests/phpunit/tests/db/ for Trac #64895 by adding the standard Keep assertEquals() inline comment.

Why?

Ticket #64895 asks contributors to either convert loose assertions to assertSame() where types matter, or keep intentional value comparisons with a short note. The remaining call in this directory compares a freshly built stdClass against a $wpdb->get_row() result, so it must stay as assertEquals().

How?

In tests/phpunit/tests/db/dbDelta.php, assertTableRowHasValue() builds (object) array( $column => $value ) and compares it with the row object returned by $wpdb->get_row(). Those are distinct object instances with the same shape, so value comparison is required. Added:

Keep assertEquals() because the objects are intentionally compared by value.

No other files under db/ contain assertEquals().

Testing Instructions

  1. Check out this branch.
  2. Run:

npm run test:php -- --test-suffix .php tests/phpunit/tests/db

  1. Confirm the suite passes. This is a comment-only change; no assertion logic was modified.

This ticket was mentioned in ​PR #13999 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#150

What?

Documents the remaining intentional assertEquals() call in tests/phpunit/tests/compat/ for Trac #64895 by adding the standard Keep assertEquals() inline comment.

Why?

Ticket #64895 asks contributors to either convert loose assertions to assertSame() where types matter, or keep intentional value comparisons with a short note. The remaining call in this directory compares DateTimeImmutable instances and must stay as assertEquals().

How?

Reviewed the remaining assertEquals() call in tests/phpunit/tests/compat/clamp.php.

test_clamp_with_datetime() compares:

  • $expected — a DateTimeImmutable from the data provider
  • the object returned by clamp( $value, $min, $max )

These are different object instances with the same calendar value, so assertSame() would fail. Kept assertEquals() and documented it with:

// Keep assertEquals() because the objects are intentionally compared by value.

No assertion logic was changed.

Testing Instructions

  1. Check out this branch.
  2. Run:
npm run test:php -- --test-suffix .php tests/phpunit/tests/compat
  1. Confirm the suite passes. This is a comment-only change; no assertion logic was modified.

Use of AI Tools

AI assistance: Yes
Tool(s): Cursor
Used for: Locating the remaining undocumented assertEquals() call and drafting the inline comment / PR description. Changes were reviewed before opening the PR.

This ticket was mentioned in ​PR #14000 on ​WordPress/wordpress-develop by ​@noruzzaman.


5 weeks ago
#151

What?

Convert loose assertion to strict assertSame() and document intentional assertEquals() calls across top-level test files in tests/phpunit/tests/ for Trac #64895.

Why?

Trac #64895 aims to reduce usage of assertEquals() in the PHPUnit test suite for WordPress 7.2.

  • In tests/phpunit/tests/functions.php, memory limit comparison compares two string values, allowing a clean conversion to strict assertSame().
  • The remaining assertions in cache.php, functions.php, json-schema.php, post.php, query.php, theme.php, and user.php intentionally compare objects by value (WP_Object_Cache, DateTime, stdClass, WP_Term, WP_Theme, or numeric string IDs from database/metadata), where assertSame() would fail due to object identity or type juggling. These are documented with the standard Keep assertEquals() inline comment.

How?

  1. In tests/phpunit/tests/functions.php:
    • Converted assertEquals( WP_MAX_MEMORY_LIMIT, $ini_limit_after ) to assertSame( WP_MAX_MEMORY_LIMIT, $ini_limit_after ).
    • Added // Keep assertEquals() because the objects are intentionally compared by value. for DateTime comparison in mysql_to_rfc3339 tests.
  2. In tests/phpunit/tests/cache.php:
    • Documented WP_Object_Cache object value comparison.
  3. In tests/phpunit/tests/json-schema.php:
    • Documented stdClass object value comparison in schema preparation test.
  4. In tests/phpunit/tests/post.php:
    • Documented stdClass object value comparison in wp_count_posts test.
  5. In tests/phpunit/tests/query.php:
    • Documented WP_Term object value comparisons in tag_queried_object tests.
  6. In tests/phpunit/tests/theme.php:
    • Documented WP_Theme object value comparisons in test_wp_get_themes_default and test_get_themes_default.
  7. In tests/phpunit/tests/user.php:
    • Documented numeric string comparisons for database IDs in magic property and user update tests.

Testing Instructions

Run PHPUnit test suite for the modified files:

npm run test:php -- tests/phpunit/tests/cache.php tests/phpunit/tests/functions.php tests/phpunit/tests/json-schema.php tests/phpunit/tests/post.php tests/phpunit/tests/query.php tests/phpunit/tests/theme.php tests/phpunit/tests/user.php
npm run test:php -- -c tests/phpunit/multisite.xml tests/phpunit/tests/cache.php tests/phpunit/tests/functions.php tests/phpunit/tests/json-schema.php tests/phpunit/tests/post.php tests/phpunit/tests/query.php tests/phpunit/tests/theme.php tests/phpunit/tests/user.php

All tests pass in both single site and multisite configurations.

This ticket was mentioned in ​PR #14001 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#152

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

What?

Aligns the existing intentional assertEquals() note in tests/phpunit/tests/xmlrpc/ with the #64895 Keep assertEquals() convention.

Why?

Ticket #64895 asks contributors to either convert loose assertions to assertSame() where types matter, or keep intentional value comparisons with a short note. In this test, wp.getTerm returns term IDs as strings (XML-RPC integer limits), while get_term() returns them as integers, so the overall structure comparison must stay as assertEquals(). Individual types are already asserted separately below.

How?

Reviewed the remaining assertEquals() call in tests/phpunit/tests/xmlrpc/wp/getTerm.php.

test_valid_term() compares:

  • $term - from get_term( ..., ARRAY_A ) (integer IDs)
  • $result - from wp.getTerm (string IDs)

Updated the existing comment to lead with the ticket’s keep convention:

Testing Instructions

npm run test:php -- --test-suffix .php tests/phpunit/tests/xmlrpc

Use of AI Tools

  • Cursor

This ticket was mentioned in ​PR #14002 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#153

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

What?

Documents the remaining intentional assertEquals() call in tests/phpunit/tests/functions/ for Trac #64895 by adding the standard Keep assertEquals() inline comment.

Why?

Ticket #64895 asks contributors to either convert loose assertions to assertSame() where types matter, or keep intentional value comparisons with a short note. In maybe_unserialize() tests, object results are already branched to assertEquals() on purpose because unserialize() returns a new instance, so it must stay as assertEquals().

How?

Reviewed the remaining assertEquals() call in tests/phpunit/tests/functions/maybeSerialize.php.

test_maybe_unserialize() already branches:

  • objects → assertEquals()
  • scalars → assertSame()

Testing Instructions

npm run test:php -- --test-suffix .php tests/phpunit/tests/functions

Use of AI Tools

Cursor

​@shailu25 commented on ​PR #13999:


5 weeks ago
#154

Closing ìn favor or #13997

​@noruzzaman commented on ​PR #13997:


5 weeks ago
#155

Thank you @mukeshpanchal27! That makes complete sense. Reusing instances in the data provider verifies that clamp() returns the exact object reference, allowing us to enforce assertSame() strictly without needing an explanatory comment. Updated in 209da21b9b.

#158 @lancewillett
5 weeks ago

In 64105:

Tests: Document post object value comparisons.

Explain why the sample permalink tests retain assertEquals() when checking that the original WP_Post properties remain unchanged.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13993

Props noruzzaman.
See #64895.

#160 @lancewillett
5 weeks ago

In 64106:

Tests: Document term value comparisons.

Explain why term tests retain assertEquals() for separate WP_Term objects and term taxonomy IDs that may be integers or numeric strings.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13996

Props noruzzaman.
See #64895.

#162 @lancewillett
5 weeks ago

In 64107:

Tests: Use strict comparisons for clamped date objects.

Reuse DateTimeImmutable instances in the data provider and use assertSame() to verify that clamp() returns the expected input or bound object.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13997

Props noruzzaman, mukesh27.
See #64895.

#164 @lancewillett
5 weeks ago

In 64108:

Tests: Use strict comparisons for database row values.

Fetch the row as an associative array in assertTableRowHasValue() and use assertSame() to check the stored column value and type.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13998

Props shailu25, mukesh27.
See #64895.

#166 @lancewillett
5 weeks ago

In 64109:

Tests: Use strict comparisons for XML-RPC term responses.

Cast the expected term IDs to strings to match the XML-RPC response contract, then use assertSame() to verify the complete response.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14001

Props shailu25, mukesh27.
See #64895.

#168 @lancewillett
5 weeks ago

In 64110:

Tests: Document unserialized object value comparisons.

Explain why maybe_unserialize() tests retain assertEquals() when comparing object values.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14002

Props shailu25, mukesh27.
See #64895.

#170 @lancewillett
5 weeks ago

In 64111:

Tests: Clarify comparisons in top-level test files.

Use assertSame() with a string expectation for the memory limit. Document intentional object-value comparisons and numeric-string differences in user properties.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14000

Props noruzzaman.
See #64895.

This ticket was mentioned in ​PR #14066 on ​WordPress/wordpress-develop by ​@shailu25.


5 weeks ago
#172

Trac ticket: #64895

What?

Replaces the remaining loose assertEquals() calls in tests/phpunit/tests/customize/nav-menu-item-setting.php with assertSame().

Expected object_id and menu_item_parent values are cast to strings first so they match the types returned from post meta by wp_setup_nav_menu_item(). Intentional object-value assertEquals() comparisons in other Customizer test files are left unchanged.

Why?

#64895 asks contributors to use strict assertions when value types matter, or document intentional loose comparisons.

#13451 kept these Customizer assertions as assertEquals() because of int/string mismatches. Casting the expected values removes that mismatch so the tests can check both value and type, following the same approach used for the XML-RPC term conversion in #14001.

How?

  1. Cast expected object_id and menu_item_parent to (string) before comparing with assertSame().
  2. Normalize object_id in the save/update fixtures the same way before the property loops.
  3. Leave documented object-value comparisons in nav-menu-setting.php and widgets.php as assertEquals().

Testing Instructions

  • npm run test:php -- --group customize
  • npm run test:php -- --filter Tests_Customize_Nav_Menu_Item_Setting

Use of AI Tools

  • Cursor

#173 @lancewillett
4 weeks ago

In 64263:

Tests: Use strict assertions for Customizer menu item metadata.

Replace remaining assertEquals() calls in tests/phpunit/tests/customize/nav-menu-item-setting.php with assertSame(). Cast expected object_id and menu_item_parent values to strings to match the metadata returned by wp_setup_nav_menu_item().

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14066

Props shailu25.
See #64895.

#175 in reply to: ↑ 93 @shailu25
4 weeks ago

I opened the following Gutenberg follow-up PRs for Trac #64895:

  • ​#84510 - phpunit/blocks/block-core-post-time-to-read-word-count.php
  • ​#84513 - phpunit/blocks/render-block-image-test.php
  • ​#84514 - phpunit/blocks/render-block-heading-test.php
  • ​#84515 - phpunit/blocks/render-block-paragraph-test.php

These replace assertEquals() with assertSame() where exact string or integer values are expected.

This ticket was mentioned in ​PR #14709 on ​WordPress/wordpress-develop by ​@devmuhib.


3 weeks ago
#176

What

Documents intentional assertEquals() comparisons by value in tests/phpunit/tests/post/wpCountPosts.php, tests/phpunit/tests/post/wpCountAttachments.php, and tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-html.php.

Why

Per maintainer guidance on Trac #64895, remaining assertEquals() calls in the test suite that compare objects or object-bearing structures across separately constructed instances should retain assertEquals() and document the intentional comparison by value:

// Keep assertEquals() because the objects are intentionally compared by value.

How

  • In tests/phpunit/tests/post/wpCountPosts.php:
    • Lines 100 and 183: Documented object comparisons for new stdClass() and stored counts objects.
    • Line 163: Documented array containing the filtered counts object passed to the wp_count_posts filter.
  • In tests/phpunit/tests/post/wpCountAttachments.php:
    • Line 198: Documented array containing the filtered counts object passed to the wp_count_attachments filter.
    • Line 228: Documented object comparison for the image/jpeg count object.
  • In tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-html.php:
    • Line 781: Documented object comparison for json_decode() state marker object.

#177 @wildworks
3 weeks ago

For assertions that compare the entire rendered HTML output, it might be better to use assertEqualHTML() instead of assertSame(). The reason is that assertEqualHTML() parses both strings with the HTML API and normalizes insignificant differences, such as the order of attributes and class names and whitespace in style attributes, before comparing them strictly with assertSame(). This keeps the comparison type-strict while preventing the tests from breaking due to harmless changes in the markup.

This ticket was mentioned in ​PR #14727 on ​WordPress/wordpress-develop by ​@shailu25.


3 weeks ago
#178

Part of: #64895

What

Replaces the remaining assertNotEquals() calls in tests/phpunit/tests/comment/ with assertNotSame() for query-count comparisons.

Updated files:

  • tests/phpunit/tests/comment/getPageOfComment.php
    • test_query_var_cache_should_be_bust_when_comment_is_added(): assertNotEquals → assertNotSame
  • tests/phpunit/tests/comment/query.php
    • test_cache_should_be_sensitive_to_parent__in(): assertNotEquals → assertNotSame
    • test_cache_should_be_sensitive_to_parent__not_in(): assertNotEquals → assertNotSame

Why

#64895 asks for strict assertions when both sides share a type. These three comparisons use integers from get_num_queries(), so assertNotSame() is appropriate. Same approach as [r63632] / [r64079].

How

  • Convert $this->assertNotEquals( $num_queries, get_num_queries() ) → $this->assertNotSame( $num_queries, get_num_queries() ) in the three cache-sensitivity tests
  • Leave other assertions in the directory unchanged

Testing instructions

  1. Start the local WordPress develop environment.
  2. Run: npm run test:php -- --test-suffix .php tests/phpunit/tests/comment/

Use of AI tools

Cursor

This ticket was mentioned in ​PR #14728 on ​WordPress/wordpress-develop by ​@shailu25.


3 weeks ago
#179

Part of: #64895

What

Replaces the remaining assertNotEquals() calls in the abilities REST controller tests with assertNotSame().

Updated files:

  • tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php
    • Pagination test: assertNotEquals( $page1_slugs, $page2_slugs ) → assertNotSame
  • tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php
    • Pagination test: assertNotEquals( $page1_names, $page2_names ) → assertNotSame

Why

#64895 asks for strict assertions when both sides share a type. These comparisons are string arrays from wp_list_pluck(), so assertNotSame() is appropriate. Same approach as [r63632] / [r64079].

How

  • Convert the two page1 vs page2 inequality checks from assertNotEquals() to assertNotSame()
  • Leave other assertions in rest-api/ unchanged

Testing instructions

  1. Start the local WordPress develop environment.
  2. Run: npm run test:php -- --filter 'Tests_REST_WpRestAbilitiesV1(Categories|List)Controller'

Use of AI tools

Cursor

This ticket was mentioned in ​PR #14729 on ​WordPress/wordpress-develop by ​@shailu25.


3 weeks ago
#180

What

Replaces the remaining assertNotEquals() calls in tests/phpunit/tests/pomo/ with assertNotSame().

Updated file:

  • tests/phpunit/tests/pomo/translationEntry.php
    • test_key(): 3 assertNotEquals → assertNotSame for Translation_Entry::key() string comparisons

Why

#64895 asks for strict assertions when both sides share a type. These comparisons are strings from Translation_Entry::key(), and the same test already uses assertSame() for the matching-key case. Same approach as [r63632] / [r64079].

How

  • Convert the three inequality checks on entry keys from assertNotEquals() to assertNotSame()
  • Leave documented object-value assertEquals() calls in the directory unchanged

Testing instructions

  1. Start the local WordPress develop environment.
  2. Run: npm run test:php -- --test-suffix .php tests/phpunit/tests/pomo/

Use of AI tools

Cursor

#181 @haritpanchal
3 weeks ago

Working on the navigation link variation builder tests.

54 assertEquals() in one file, phpunit/blocks/class-build-variation-for-navigation-link-test.php,
which is all of them in that file.

Taking the one file rather than the whole navigation link group, since 54 is already a large
diff and the other navigation files have several unrelated pull requests open against them.
I checked the open Gutenberg pull requests first and none of them touch this file.

Note the inventory has moved since comment 89. On trunk today there are 120 assertEquals()
left rather than 154, after the conversions merged by shail-mehta and noruzzamans and the four
in #83619. After this file and my open #83777 for the style engine, what remains is
class-wp-theme-json-test.php (35), class-block-library-navigation-link-test.php (16),
render-block-navigation-submenu-test.php (5), class-wp-navigation-block-renderer-test.php (4),
the experimental REST comments controller test (2) and class-wp-block-templates-registry-test.php
(1).

This ticket was mentioned in ​PR #14836 on ​WordPress/wordpress-develop by ​@hmbashar.


2 weeks ago
#182

Summary

In tests/phpunit/tests/post/wpCountPosts.php and tests/phpunit/tests/post/wpCountAttachments.php, several assertEquals() calls compare stdClass objects or arrays containing objects by value.

These cannot be replaced with assertSame() because strict instance identity checks would fail for freshly-constructed or independently-retrieved objects. For example:

  • assertEquals( new stdClass(), wp_count_posts( 'not_a_post_type' ) ) — two separate instances, same shape
  • assertEquals( (object) array( 'publish' => 5 ), $stored_counts ) — object value comparison
  • assertEquals( array( $expected_counts, 'page', 'readable' ), $args[0] ) — array containing a stdClass

This PR adds // Keep assertEquals() because ... annotations to document that each call was reviewed and intentionally kept as-is, consistent with the approach used elsewhere in the test suite (e.g. tests/phpunit/tests/cron.php, tests/phpunit/tests/term/wpInsertTerm.php).

Changes

  • tests/phpunit/tests/post/wpCountPosts.php: 3 annotations added
  • tests/phpunit/tests/post/wpCountAttachments.php: 2 annotations added

---

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See ​GitHub Pull Requests for Code Review in the Core Handbook for more details.

This ticket was mentioned in ​PR #14838 on ​WordPress/wordpress-develop by ​@hmbashar.


2 weeks ago
#183

Summary

In tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-html.php, one assertEquals() call compares a cast-to-object array with the result of json_decode():

$this->assertEquals(
    (object) array( 'wpServerHtml' => true ),
    json_decode( $this->printed_client_data() )->state->test->html,
    'Expected the token to print as the marker.'
);

These are two separate object instances with equal values. assertSame() would fail on an identity check, so assertEquals() is intentionally used for value comparison.

This PR adds a // Keep assertEquals() because ... annotation to document the review, consistent with the approach used elsewhere in the test suite.

Changes

  • tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-html.php: 1 annotation added

---

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See ​GitHub Pull Requests for Code Review in the Core Handbook for more details.

​@hmbashar commented on ​PR #14836:


2 weeks ago
#184

Closing in favor of #14709 which covers the same files.

​@hmbashar commented on ​PR #14838:


2 weeks ago
#185

Closing in favor of #14709 which covers the same files.

This ticket was mentioned in ​PR #14853 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#186

Part of: #64895

What

Replaces the remaining assertNotEquals() calls in tests/phpunit/tests/adminbar.php with assertNotSame() for profile URL comparisons.

Updated methods:

  • test_admin_bar_contains_correct_links_for_users_with_no_role(): assertNotEquals → assertNotSame
  • test_admin_bar_contains_correct_links_for_users_with_no_role_on_network(): assertNotEquals → assertNotSame

Why

#64895 asks for strict assertions when both sides share a type. These comparisons are URL strings (get_admin_url() / user_admin_url() vs admin_url()), so assertNotSame() is appropriate. Same approach as [r63632] / [r64079].

How

  • Convert the two profile URL inequality checks from assertNotEquals() to assertNotSame()
  • Leave other assertions in the file unchanged

Testing instructions

  1. Start the local WordPress develop environment.
  2. Run: npm run test:php -- --filter Tests_AdminBar
  3. For the multisite cases: npm run test:php -- --group ms-required --filter Tests_AdminBar

Use of AI tools

Cursor

This ticket was mentioned in ​PR #14854 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#187

Part of: #64895

What

Replaces the remaining assertNotEquals() call in tests/phpunit/tests/media.php with assertNotSame() for the prepared attachment URL check.

Updated method:

  • test_wp_prepare_attachment_for_js(): assertNotEquals( '', $prepped['url'] ) → assertNotSame( '', $prepped['url'] )

Why

#64895 asks for strict assertions when both sides share a type. The prepared attachment url is a string, so assertNotSame() is appropriate.

How

  • Convert the empty-string URL inequality check from assertNotEquals() to assertNotSame()
  • Leave other assertions in the file unchanged

Testing instructions

  1. Start the local WordPress develop environment.
  2. Run: npm run test:php -- --filter test_wp_prepare_attachment_for_js

Use of AI tools

Cursor

This ticket was mentioned in ​PR #14855 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#188

Part of: #64895

What

Replaces the remaining assertNotEquals() call in tests/phpunit/tests/meta.php with assertNotSame() for the user login comparison.

Updated method:

  • test_user_metadata_not_exists(): assertNotEquals → assertNotSame for user_login

Why

#64895 asks for strict assertions when both sides share a type. These are user_login strings, so assertNotSame() is appropriate.

How

  • Convert the author vs found-user login inequality check from assertNotEquals() to assertNotSame()
  • Leave other assertions in the file unchanged

Testing instructions

  1. Start the local WordPress develop environment.
  2. Run: npm run test:php -- --filter test_user_metadata_not_exists

Use of AI tools

Cursor

This ticket was mentioned in ​PR #14857 on ​WordPress/wordpress-develop by ​@hmbashar.


2 weeks ago
#189

Description

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/file.php where values are scalar (strings, URLs, integers, booleans). Follow-up to Trac #64895.

assertNotSame() is stricter — it checks both value and type equality, preventing false passes from type coercion.

Changes

  • tests/phpunit/tests/file.php: Replace assertNotEquals() with assertNotSame() for scalar comparisons

How to test

  1. Run the affected test class: phpunit tests/phpunit/tests/file.php
  2. All tests should pass

See Trac #64895

<details>
<summary>Use of AI Tools</summary>

AI assistance: Yes
Tool(s): Claude
Model(s): claude-sonnet-5-5
Used for: Code implementation and test; reviewed and verified by contributor.

</details>

This ticket was mentioned in ​PR #14868 on ​WordPress/wordpress-develop by ​@hmbashar.


2 weeks ago
#190

Description

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/link.php where values are scalar (strings, URLs). Follow-up to Trac #64895.

assertNotSame() is stricter — it checks both value and type equality, preventing false passes from type coercion.

Changes

  • tests/phpunit/tests/link.php: Replace assertNotEquals() with assertNotSame() for scalar comparisons

How to test

  1. Run the affected test class: phpunit tests/phpunit/tests/link.php
  2. All tests should pass

See Trac #64895

<details>
<summary>Use of AI Tools</summary>

AI assistance: Yes
Tool(s): Claude
Model(s): claude-sonnet-5-5
Used for: Code implementation and test; reviewed and verified by contributor.

</details>

#191 @SergeyBiryukov
2 weeks ago

In 64773:

Tests: Use assertNotSame() for scalar comparison in link tests.

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/link.php where the values are scalar (strings, URLs).

assertNotSame() is stricter — it checks both value and type equality, preventing false passes from type coercion.

Follow-up to r25030, r48937.

Props hmbashar, rejaulalomkhan.
See #64895.

​@SergeyBiryukov commented on ​PR #14868:


2 weeks ago
#192

Thanks for the PR! Merged in r64773.

#193 @lancewillett
2 weeks ago

In 64778:

Tests: Use strict comparisons for comment query counts.

Use assertNotSame() when checking that comment queries with different types or parent filters issue another database query. Both operands come from the integer query counter returned by get_num_queries().

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14727

Props shailu25.
See #64895.

#195 @lancewillett
2 weeks ago

In 64779:

Tests: Use strict comparisons for abilities pagination.

Use assertNotSame() to compare page-one and page-two identifier arrays in the abilities and ability categories REST controller tests.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14728

Props shailu25.
See #64895.

#197 @lancewillett
2 weeks ago

In 64780:

Tests: Use strict comparisons for POMO translation keys.

Use assertNotSame() for differing Translation_Entry::key() values. Preserve the checks that context and singular text distinguish keys, while plural text does not.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14729

Props shailu25.
See #64895.

#199 @lancewillett
2 weeks ago

In 64781:

Tests: Use strict comparisons for admin bar profile URLs.

Use assertNotSame() for profile URL comparisons in multisite admin bar tests. Preserve the checks that users without a role on the current site receive links to the appropriate profile screen.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14853

Props shailu25.
See #64895.

#201 @lancewillett
2 weeks ago

In 64782:

Tests: Use a strict comparison for the attachment URL.

Use assertNotSame() when checking that wp_prepare_attachment_for_js() supplies a non-empty URL for an attachment without media.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14854

Props shailu25.
See #64895.

#202 @lancewillett
2 weeks ago

In 64783:

Tests: Use a strict comparison for user meta query logins.

Use assertNotSame() when checking that a NOT EXISTS user meta query excludes the fixture author.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14855

Props shailu25.
See #64895.

​@mukesh27 commented on ​PR #14854:


2 weeks ago
#204

Committed at r64782

This ticket was mentioned in ​PR #14975 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#205

Trac ticket: #64895

Description

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/customize/widgets.php for the filtered dynamic sidebar params comparison. Follow-up to Trac #64895.

This was the only convertible assertNotEquals() call in the file. The remaining assertEquals() compares objects by value and is already documented.

Changes

  • tests/phpunit/tests/customize/widgets.php: Replace assertNotEquals() with assertNotSame()

How to test

  1. Run: phpunit --group customize --filter test_filter_dynamic_sidebar_params or: phpunit tests/phpunit/tests/customize/widgets.php
  2. All tests should pass

Use of AI Tools

  • Cursor

This ticket was mentioned in ​PR #14976 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#206

Trac ticket: #64895

What

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/term/ for scalar comparisons (term IDs, names, and cache timestamps).

Why

Per maintainer guidance on Trac #64895, loose assertNotEquals() calls should use assertNotSame() for consistency with strict assertion cleanup across the test suite.

Remaining assertEquals() calls in this directory compare objects by value (or numeric string/int TT IDs) and are already documented.

How

  • tests/phpunit/tests/term/splitSharedTerm.php: 5 replacements
  • tests/phpunit/tests/term/getTerms.php: 2 replacements
  • tests/phpunit/tests/term/wpInsertTerm.php: 2 replacements
  • tests/phpunit/tests/term/cache.php: 1 replacement
  • tests/phpunit/tests/term/wpUpdateTerm.php: 1 replacement

Testing Instructions

  1. Run: phpunit tests/phpunit/tests/term/
  2. All tests should pass

Use of AI Tools

  • Cursor

This ticket was mentioned in ​PR #14978 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#207

Trac ticket: #64895

What

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/query/ for array comparisons (search terms and posts).

Why

Per maintainer guidance on Trac #64895, loose assertNotEquals() calls should use assertNotSame() for consistency with strict assertion cleanup across the test suite.

Remaining assertEquals() calls in this directory compare objects by value and are already documented.

How

  • tests/phpunit/tests/query/search.php: 4 replacements
  • tests/phpunit/tests/query/cacheResults.php: 1 replacement

Testing Instructions

  1. Run: phpunit tests/phpunit/tests/query/
  2. All tests should pass

Use of AI Tools

  • Cursor

This ticket was mentioned in ​PR #14979 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#208

Trac ticket: #64895

What

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/link/ for adjacent post comparisons.

Why

Per maintainer guidance on Trac #64895, loose assertNotEquals() calls should use assertNotSame() for consistency with strict assertion cleanup across the test suite.

Remaining assertEquals() calls in this directory compare objects by value and are already documented.

How

  • tests/phpunit/tests/link/getAdjacentPost.php: 4 replacements

Testing Instructions

  1. Run: phpunit tests/phpunit/tests/link/
  2. All tests should pass

Use of AI Tools

  • Cursor

This ticket was mentioned in ​PR #14982 on ​WordPress/wordpress-develop by ​@shailu25.


2 weeks ago
#209

Trac ticket: #64895

What

Converts assertNotEquals() to assertNotSame() in remaining top-level PHPUnit test files for scalar and array comparisons.

Why

Per maintainer guidance on Trac #64895, loose assertNotEquals() calls should use assertNotSame() for consistency with strict assertion cleanup across the test suite.

How

  • tests/phpunit/tests/post.php: 2 replacements
  • tests/phpunit/tests/db.php: 2 replacements
  • tests/phpunit/tests/widgets.php: 1 replacement
  • tests/phpunit/tests/rewrite.php: 1 replacement

Testing Instructions

  1. Run:
    • phpunit tests/phpunit/tests/post.php
    • phpunit tests/phpunit/tests/db.php
    • phpunit tests/phpunit/tests/widgets.php
    • phpunit tests/phpunit/tests/rewrite.php
  2. All tests should pass

Use of AI Tools

  • Cursor

#210 @lancewillett
2 weeks ago

In 64804:

Tests: Use strict inequality in Customizer tests.

Use assertNotSame() for scalar and array comparisons in Customizer tests, including menu item counts, changeset data, and sidebar parameters.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14975

Props shailu25.
See #64895.

#212 @lancewillett
2 weeks ago

In 64805:

Tests: Use strict inequality in term tests.

Use assertNotSame() when comparing term IDs, names, cache timestamps, and the term count filter sentinel.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14976

Props shailu25.
See #64895.

#214 @lancewillett
2 weeks ago

In 64806:

Tests: Use strict inequality in search query tests.

Use assertNotSame() for search term arrays and attachment ID results. Retain value-based comparisons for query results containing objects.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14978

Props shailu25.
See #64895.

#216 @lancewillett
2 weeks ago

In 64807:

Tests: Compare adjacent post IDs with strict inequality.

Compare post IDs with assertNotSame() to verify that adjacent post queries exclude the current post. Retain value-based comparisons for the expected post objects.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14979

Props shailu25.
See #64895.

#218 @lancewillett
2 weeks ago

In 64808:

Tests: Use strict inequality in top-level test files.

Use assertNotSame() for scalar and array comparisons in database, post count, rewrite, and widget tests.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14982

Props shailu25.
See #64895.

​@lancewillett commented on ​PR #14975:


2 weeks ago
#220

Posting the review completed before landing; GitHub authentication prevented posting it at the time.

Reviewed the current diff and the prior Copilot feedback. The compared scalar values and arrays have consistent types; object-value comparisons remain where needed. No blocker found.

The batch passed focused randomized single-site (32 tests, 408 assertions) and multisite (33 tests, 414 assertions) runs, plus PHPCS for all 15 files. Broader randomized runs reproduced three existing closed-database-handle errors, including on the unpatched baseline. CI is green.

<sub>AI review · <code>gpt-6</code></sub>

​@lancewillett commented on ​PR #14976:


2 weeks ago
#221

Posting the review completed before landing; GitHub authentication prevented posting it at the time.

Reviewed the current diff and the prior Copilot feedback. The compared scalar values and arrays have consistent types; object-value comparisons remain where needed. No blocker found.

The batch passed focused randomized single-site (32 tests, 408 assertions) and multisite (33 tests, 414 assertions) runs, plus PHPCS for all 15 files. Broader randomized runs reproduced three existing closed-database-handle errors, including on the unpatched baseline. CI is green.

<sub>AI review · <code>gpt-6</code></sub>

​@lancewillett commented on ​PR #14978:


2 weeks ago
#222

Posting the review completed before landing; GitHub authentication prevented posting it at the time.

Reviewed the current diff and the prior Copilot feedback. The compared scalar values and arrays have consistent types; object-value comparisons remain where needed. No blocker found.

The batch passed focused randomized single-site (32 tests, 408 assertions) and multisite (33 tests, 414 assertions) runs, plus PHPCS for all 15 files. Broader randomized runs reproduced three existing closed-database-handle errors, including on the unpatched baseline. CI is green.

<sub>AI review · <code>gpt-6</code></sub>

​@lancewillett commented on ​PR #14979:


2 weeks ago
#223

Posting the review completed before landing; GitHub authentication prevented posting it at the time.

Reviewed the current diff and the prior Copilot feedback. The compared scalar values and arrays have consistent types; object-value comparisons remain where needed. No blocker found.

The batch passed focused randomized single-site (32 tests, 408 assertions) and multisite (33 tests, 414 assertions) runs, plus PHPCS for all 15 files. Broader randomized runs reproduced three existing closed-database-handle errors, including on the unpatched baseline. CI is green.

<sub>AI review · <code>gpt-6</code></sub>

​@lancewillett commented on ​PR #14982:


2 weeks ago
#224

Posting the review completed before landing; GitHub authentication prevented posting it at the time.

Reviewed the current diff and the prior Copilot feedback. The compared scalar values and arrays have consistent types; object-value comparisons remain where needed. No blocker found.

The batch passed focused randomized single-site (32 tests, 408 assertions) and multisite (33 tests, 414 assertions) runs, plus PHPCS for all 15 files. Broader randomized runs reproduced three existing closed-database-handle errors, including on the unpatched baseline. CI is green.

<sub>AI review · <code>gpt-6</code></sub>

#225 @lancewillett
2 weeks ago

In 64825:

Tests: Use strict inequality for unique filenames.

Use assertNotSame() when comparing the two filename strings returned by wp_unique_filename(). Preserve the checks that both files can be created and written.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14857

Props hmbashar, mukesh27.
See #64895.

#227 @lancewillett
2 weeks ago

In 64826:

Tests: Document intentional object value comparisons.

Explain why post and attachment count tests and the Interactivity API HTML test retain assertEquals() when comparing separate objects by value.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14709

Props devmuhib, huzaifaalmesbah.
See #64895.

This ticket was mentioned in ​PR #15209 on ​WordPress/wordpress-develop by ​@shailu25.


11 days ago
#229

Trac ticket: #64895

What?

Documents the remaining intentional assertEquals() object value comparisons in Abilities API and wp_clean_plugins_cache() tests.

Why?

assertEquals() does not compare types, so Trac #64895 replaces it with type-strict assertions where safe. These calls compare different object instances by value (WP_Error, update_plugins transient), so they must stay as assertEquals(). Annotating them prevents accidental conversion in later cleanups.

How?

Added the existing ticket comment style above each call:

// Keep assertEquals() because the objects are intentionally compared by value.

Touched files:

  • tests/phpunit/tests/abilities-api/wpAbility.php
  • tests/phpunit/tests/admin/includes/plugin/wpCleanPluginsCache.php

No assertion logic was changed.

Testing Instructions

  1. Check out this branch on current trunk.
  2. Run the affected tests:
npm run test:php -- --filter 'Tests_Abilities_API_WpAbility::test_input_coercion_errors|Tests_Admin_Includes_Plugin_WpCleanPluginsCache'

Expected: tests pass with no behavior change (comments only).

Use of AI Tools

  • Cursor

#230 @lancewillett
11 days ago

In 65079:

Tests: Document intentional object value comparisons.

Explain why the Abilities API coercion error and plugin update transient assertions retain assertEquals() to compare objects by value rather than identity.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15209

Props shailu25.
See #64895.

This ticket was mentioned in ​PR #15332 on ​WordPress/wordpress-develop by ​@noruzzaman.


9 days ago
#232

See Trac Ticket: #64895 https://core.trac.wordpress.org/ticket/64895

Description

In tests/phpunit/tests/block-templates/WpBlockTemplatesRegistry.php, test_register_template() calls assertSame() with inverted arguments where $actual was placed before $expected.

This PR corrects the parameter ordering so $expected precedes $actual, ensuring adherence to standard PHPUnit conventions and producing accurate diff output upon assertion failure.

Related upstream Gutenberg PR: ​https://github.com/WordPress/gutenberg/pull/86144

cc @lancewillett

​@rejaulalomkhan commented on ​PR #15332:


9 days ago
#233

@noruzzamans Thanks for working on this PR. LGTM!

#234 @lancewillett
8 days ago

In 65185:

Tests: Correct block template slug assertion argument order.

Pass the expected slug before the actual value in test_register_template() so PHPUnit reports failures correctly.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15332

Props noruzzaman, rejaulalomkhan.
See #64895.

Note: See TracTickets for help on using tickets.