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
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, becausedhas no matching entry inproperties, nopatternProperties, andadditionalPropertiesis unset, so it is never coerced.- The top-level
'b' => 1in that same test stays an integer for the same reason. 'b' => 1intest_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
@
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:
↓ 7
@
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/
#7
in reply to: ↑ 6
@
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:
- 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.
- 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.
- 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.
- 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.
- 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.
@lancewillett commented on PR #13451:
2 months ago
#10
#11
@
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
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_idfails bothtest_ignore_idtests at the newassertIsString(), and passes without it._prepare_term()returning all four IDs as integers failstest_valid_term. With the mutation in place but the newassertIsString()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.
@lancewillett commented on PR #13503:
2 months ago
#16
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 assertsassertSame( (string) $value, get_site_option( $key ) ). A fresh DB read returns scalar option values as strings regardless of what was stored, even though$valuewas set as int0. Confirmed by mutation: removing the cast fails withFailed 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-readstdClass/array against a literal built for the assertion. The DB round trip never returns the same instance, soassertSame()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 isget_option( 'permalink_structure' ): on single site the test bootstrap never seeds that option, so it resolves tofalse; on multisite the site is created via the real installer, which seeds it to''viapopulate_options(). One literal can't match both, so it stays loose.wpPrimeOptionCaches.php— already branches onis_object()to pickassertEquals()/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.
@lancewillett commented on PR #13516:
2 months ago
#20
#22
@
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.
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 toassertSame(). Each compares a string literal againstWP_HTML_Tag_Processor::get_updated_html(), which has a strict: stringreturn-type declaration — both sides are guaranteed strings.wpBlockBindingsRegistry.php— 1 of 5 converts:$result->uses_contextis asserted against a plain string array. The constructor storesuses_contextunmodified (`$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) andwpBlockBindingsRegistry.php(4 of 5) all compare a freshly-new'dWP_Block_Bindings_Sourceagainst one the registry constructed and stored internally (register()'s own `new WP_Block_Bindings_Source(...), returned byunregister()`/get_all_registered()/get_registered()). These are always different object instances with matching property values by design, soassertSame()would fail on identity alone.test_get_all_registered()inregister.phpadditionally mixes identical-reference entries (the global core sources, fetched both sides viaget_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.
@lancewillett commented on PR #13520:
8 weeks ago
#26
#27
@
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.
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, theWP_Interactivity_API_Directives_Processorinstance 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 toget_updated_html(): string(WP_HTML_Tag_Processor, which this class extends), the same strict return-type contract used in theblock-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 useassertSame()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.
@lancewillett commented on PR #13528:
8 weeks ago
#32
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_Querywithfields => 'ID'(or'') fills$resultsvia$wpdb->get_col(), so it returns user IDs as numeric strings while the factory returns ints. Expected IDs are now(string)-cast. The twoorderby=includetests 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) — theprepare_query()test'sassertNotEquals()calls becomeassertNotSame(); 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_authoris@var string, so these assert(string) $user_id. TheassertNotEquals( $user1->ID, $post->post_author )needed the cast too: without itassertNotSame()compares int to string and can never fail. Confirmed by mutation: withremove_user_from_blog()reassigning to$user1, the cast version fails and the uncast version passes.multisite.php—WP_Sitespam/archived/deletedare@var string, sotest_get_blogs_of_user()asserts'1'.capabilities.php— intest_user_level_update(), a freshWP_Userreadsuser_levelfrom user meta via__get(), so it is'2'. Afterset_role(),update_user_level_from_caps()assigns an int, which is why the sibling assertions already useassertSame( 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 constructedWP_Roleagainst the oneWP_Rolesbuilt; different instances by design.updateUserCaches.php(2 assertions) — compare a$wpdb->get_row()object against the cached row.WP_Object_Cacheclones objects on set and get, soassertSame()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_Querywithfields => 'ID'(or'') fills$resultsvia$wpdb->get_col(), so it returns user IDs as numeric strings while the factory returns ints. Expected IDs are now(string)-cast. The twoorderby=includetests 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) — theprepare_query()test'sassertNotEquals()calls becomeassertNotSame(); 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_authoris@var string, so these assert(string) $user_id. TheassertNotEquals( $user1->ID, $post->post_author )needed the cast too: without itassertNotSame()compares int to string and can never fail. Confirmed by mutation: withremove_user_from_blog()reassigning to$user1, the cast version fails and the uncast version passes.multisite.php—WP_Sitespam/archived/deletedare@var string, sotest_get_blogs_of_user()asserts'1'.capabilities.php— intest_user_level_update(), a freshWP_Userreadsuser_levelfrom user meta via__get(), so it is'2'. Afterset_role(),update_user_level_from_caps()assigns an int, which is why the sibling assertions already useassertSame( 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 constructedWP_Roleagainst the oneWP_Rolesbuilt; different instances by design.updateUserCaches.php(2 assertions) — compare a$wpdb->get_row()object against the cached row.WP_Object_Cacheclones objects on set and get, soassertSame()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.
@lancewillett commented on PR #13545:
8 weeks ago
#36
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 insite.php— all compare an expected int againstWP_Site::$blog_id(or the same object accessed viaget_dashboard_blog()).$blog_idis 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) forWP_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 withFailed asserting that '0' is identical to 0.site.php—$cap_key(WP_User::$cap_key, always a string) andWP_Site::$pathcomparisons convertassertNotEquals()→assertNotSame()directly; both sides are already the same type.
Left as assertEquals(), no changes:
network.php(2) —get_blog_count()is backed byget_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 toassertSame()failed in opposite directions on the two tests (1vs'1'and'3'vs3), so they stay loose.site.php(6) — all compare awp_cache_get()result (or the object just passed towp_cache_set()) against the freshly-cached value.WP_Object_Cache::set()andget()bothcloneany object argument (confirmed inclass-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.
@lancewillett commented on PR #13558:
8 weeks ago
#40
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.phpTests_Comment_Pingback::test_pingback- ChangedassertEqualstoassertSamebecause the expected and actual values produce identical arrays.
Tests_Comment_Pingback::test_pingback_no_ping_back & Tests_Comment_Pingback::test_pingback_error_response- ChangedassertEqualstoassertSamebecause 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- ChangedassertEqualstoassertSameand cast the expected value ($post_id) from an integer to a string because theWP_Comment::comment_IDis a numeric string.
Test_Comment_Query::test_get_comments_by_user- ChangedassertEqualstoassertSameand cast the expected value ($users) from an integer to a string because theWP_Comment::user_idis a numeric string.
Test_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_ASCandTest_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_DESC- ChangedassertEqualstoassertSameand cast the expected array value ($comments) from an integer to a string because theWP_Comment::comment_IDis a numeric string.
Test_Comment_Query::test_comment_query_object- KeptassertEqualsbecause the expected and actual output give different object instances but the same values.
Trac ticket: #64895
Use of AI Tools
N/A
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_idis the return of the test factory'swp_insert_comment(), which is `(int) $wpdb->insert_id.WP_Comment::$comment_IDis documentednumeric-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 doesarray_map( 'intval', $this->posts ), so results are real ints. The test's$onevariable happens to be pre-cast to(string)for use inpost__in, which is unrelated to the result type — cast to(int)at the assertion site instead. Proven necessary by mutation: removing the cast fails with `Expected: Array(0 => '38') / Actual: Array(0 => 38)`.setupPostdata.php— the one comparison againststrip_ws( $content )converts directly toassertNotSame(); both sides are plain strings.
Left as assertEquals()/assertNotEquals(), no changes:
isTerm.php(10) — every case compares a *fresh*get_queried_object()orget_term()call against a term object obtained earlier in the same test. Proven by mutation: converting one toassertSame()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 withWP_User: a factory-created user vs. a separateget_userdata()call insideWP_Query::generate_postdata().cacheResults.php(1) — already carries its own comment explaining exactly why it must stayassertNotEquals()rather thanassertNotSame(): 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.phpTests_Comment_Pingback::test_pingback- ChangedassertEqualstoassertSamebecause the expected and actual values produce identical arrays.
Tests_Comment_Pingback::test_pingback_no_ping_back & Tests_Comment_Pingback::test_pingback_error_response- ChangedassertEqualstoassertSamebecause 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- ChangedassertEqualstoassertSameand cast the expected value ($comment_id) from an integer to a string because theWP_Comment::comment_IDis a numeric string.
Test_Comment_Query::test_get_comments_by_user- ChangedassertEqualstoassertSameand cast the expected value ($users) from an integer to a string because theWP_Comment::user_idis a numeric string.
Test_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_ASCandTest_Comment_Query::test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_DESC- ChangedassertEqualstoassertSameand cast the expected array value ($comments) from an integer to a string because theWP_Comment::comment_IDis a numeric string.
Test_Comment_Query::test_comment_query_object- KeptassertEqualsbecause 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 #13601:
7 weeks ago
#49
Changes look good. I fixed a minor wording issue raised by Copilot in https://github.com/WordPress/wordpress-develop/pull/13601/commits/b2dbaf139a9240d1f040722eed457119bda30e82
@lancewillett commented on PR #12613:
7 weeks ago
#50
Changes look good to land.
@lancewillett commented on PR #13600:
7 weeks ago
#52
@lancewillett commented on PR #12613:
7 weeks ago
#54
@lancewillett commented on PR #13601:
7 weeks ago
#56
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
@
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 existingassertSame()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()callswp_set_object_terms()` twice with identical arguments and asserted the two results were equal — butwp_insert_term()'s brand-new-term path does `$tt_id = (int) $wpdb->insert_idwhile its own early-return path (andterm_exists()`, hit on the second call since the term now exists) returns anumeric-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 nointval()mapping (unlike theterm_idsit queries by, a few lines above in the same function), so it's always strings.user.php(5 of 7) —WP_User::$IDis a real declared property, cast to int ininit(). ButWP_User::get_data_by()and theuserslugscache entry set byupdate_user_caches()both use the raw DB row instead (confirmed by readingupdate_user_caches(), which explicitly reassigns$user = $user->data— the raw stdClass — before caching), soIDthere is a string.use_sslanduser_levelare 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, whilerest_parse_date()always returnsint. 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']vsparse_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 freshstdClass` every call, never the same instance as the test's own(object) array(...).query.php(2) — the familiarget_queried_object()/get_term()identity-mismatch pattern already established on this ticket for thequery/directory.cache.php(1) — compares a freshlynew WP_Object_Cache()against a different global instance created bywp_cache_init().theme.php(2) —wp_get_theme()always doesreturn 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_themesarray and already useassertSame()successfully).json-schema.php(1) — compares a freshnew stdClass()(representing an empty JSON object) against another freshnew stdClass()built bywp_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()andtest_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 asmultisite/site.php'stest_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
@
7 weeks ago
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 sameget_option( 'default_category' )(string) vs.post_category[0](int) pattern already established forterm.phpon 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_authoris documented `@var string, andget_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 doesreturn (string) $thumbnail_id;on its success path (traced directly inrevision.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()(viaget_metadata_by_mid()) does a fresh$wpdb->get_row()every call — a newstdClassinstance each time, so identity alone rules outassertSame()regardless of property types.getPageByPath.php(2) — both compare aget_post()-obtainedWP_Postagainst a separateget_page_by_path()-returned one; the familiarget_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->labelsproperty fromstdClassto a plainarrayas a side effect ($data_object->labels = (array) $data_object->labels;, traced inpost.php).$before(captured pre-mutation) is an object;$after(post-mutation) is an array — genuinely different *types* by design, soassertSame()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.
@lancewillett commented on PR #13649:
7 weeks ago
#65
@lancewillett commented on PR #13659:
7 weeks ago
#66
@lancewillett commented on PR #12583:
7 weeks ago
#68
@lancewillett commented on PR #13652:
7 weeks ago
#70
#71
@
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']vsnew stdClass(), and vs(object) $user->allcaps/(object) $user->caps: always distinct object instances, compared by value only.rest-block-renderer-controller.php(1) — two independentjson_decode()calls (without thetruearg) produce distinctstdClasstrees each time; compared by value only.wpRestTemplatesController.php(1) — compares againstnew 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.
@lancewillett commented on PR #13683:
7 weeks ago
#74
#75
@
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_authoris populated raw from the database and is documented@var string. Removing the cast fails withFailed asserting that '3' is identical to 3.admin/wpCommentsListTable.php—WP_Comment::$comment_IDis a numeric string while the comment factory returns an integer. Fails withFailed asserting that '6' is identical to 6.feed/atom.php— the enclosurelengthis read out of parsed XML as a string, while the fixture declares it as integer318465. The siblinghrefandtypeassertions on the same lines already usedassertSame(). Fails withFailed asserting that '318465' is identical to 318465.http/base.php— theContent-Lengthresponse 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) andformatting/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) — comparesclone $postagainst$postto proveget_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) —DateTimeImmutableinstances built separately in the data provider.functions/maybeSerialize.php(1) — already branches onis_object()and selectsassertEquals()orassertSame()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.
@lancewillett commented on PR #13756:
7 weeks ago
#78
Nice work, @haritpanchal
#79
@
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.
@lancewillett commented on PR #11707:
7 weeks ago
#83
PR #11707 landed with https://core.trac.wordpress.org/changeset/63935
@lancewillett commented on PR #13651:
7 weeks ago
#84
PR #13651 landed with https://core.trac.wordpress.org/changeset/63936
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:
- When the terms don't exist,
wp_insert_term()creates the term and returns the term taxonomy ID as an int. - 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
@lancewillett commented on PR #13769:
6 weeks ago
#87
PR #13769 landed in https://core.trac.wordpress.org/changeset/63944
#88
@
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
@
6 weeks ago
There is a concrete Gutenberg follow-up here, and volunteers are welcome to pick it up.
- Start with a small Gutenberg PR syncing four assertions already converted in [63934]:
- Layout container hash: compare the expected and actual class strings with
assertSame(). - Template unregister: assert that the same registered object is returned.
- Block-node paths and paths with variations: use strict array comparisons.
- Layout container hash: compare the expected and actual class strings with
- 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.
#90
@
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.
#91
@
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
#92
@
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:
↓ 175
@
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 / 7link/: 29 / 1- top-level files in
tests/phpunit/tests/: 18 / 8 rest-api/: 16 / 5query/: 15 / 3customize/: 14 / 3pomo/: 10 / 2option/: 9 / 6multisite/: 8 / 2bookmark/: 7 / 1post/: 6 / 4block-bindings/: 6 / 2formatting/: 5 / 2abilities-api/: 4 / 2user/: 3 / 2- one or two each in
admin/,comment/,compat/,db/,functions/andxmlrpc/ 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.
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
$bookmarkwith$actual_cachereturned fromwp_cache_get(). - Line 235: Comparing
$expectedobject with$actual_bookmarkreturned fromget_bookmark(). - Line 242: Comparing
self::$bookmarkwith$actual_cachereturned fromwp_cache_get(). - Line 293: Comparing
$expectedobject with$actual_bookmarkreturned from database row. - Line 300: Comparing
self::$bookmarkwith$actual_cachereturned fromwp_cache_get().
All 5 comparisons intentionally compare objects by value rather than reference identity:
WP_Object_Cache::get()explicitly clones objects upon retrieval (return clone $this->cache[ $group ][ $key ];), meaning$actual_cacheand cached bookmark objects are distinct instances from the originals.- In database fetch paths,
$actual_bookmarkis a distinctstdClassobject instance created from$wpdb->get_row(). - 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
@lancewillett commented on PR #13832:
6 weeks ago
#96
PR #13832 landed in https://core.trac.wordpress.org/changeset/64015
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
$expectedarray ofWP_Block_Bindings_Sourceinstances with$registered. - Line 100: Comparing expected
new WP_Block_Bindings_Source(...)with$resultfromunregister_block_bindings_source().
- Line 83: Comparing
tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php:- Line 192: Comparing expected
new WP_Block_Bindings_Source(...)with$resultfromWP_Block_Bindings_Registry::register(). - Line 238: Comparing expected
new WP_Block_Bindings_Source(...)with$resultfromWP_Block_Bindings_Registry::unregister(). - Line 277: Comparing
$expectedarray ofWP_Block_Bindings_Sourceinstances with$registered. - Line 322: Comparing expected
new WP_Block_Bindings_Source(...)with$resultfromWP_Block_Bindings_Registry::get_registered().
- Line 192: Comparing expected
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$resultfromWP_Abilities_Registry::register().
- Line 519: Comparing
tests/phpunit/tests/abilities-api/wpRegisterAbility.php:- Line 523: Comparing
new WP_Ability(...)with$resultfromwp_unregister_ability(). - Line 586: Comparing
new WP_Ability(...)with$resultfromwp_get_ability(). - Line 705: Comparing
$expectedarray ofWP_Abilityinstances with$resultfromwp_get_abilities().
- Line 523: Comparing
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.
@lancewillett commented on PR #13902:
6 weeks ago
#101
PR #13902 landed in https://core.trac.wordpress.org/changeset/64031
@lancewillett commented on PR #13903:
6 weeks ago
#103
PR #13903 landed in https://core.trac.wordpress.org/changeset/64032
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_entrywith$mo->entries[ $plural_entry->key() ]. - Line 71: Comparing
$single_entrywith$mo->entries[ $single_entry->key() ]. - Line 141: Comparing
$entrywith$again->entries[ $entry->key() ]after exporting and importing an MO file.
- Line 61: Comparing
tests/phpunit/tests/pomo/po.php:- Lines 285, 295, 303, 313, 324, 327: Comparing expected
Translation_Entryobjects with entries parsed from PO files. - Line 388: Comparing
$po->entriesarray ofTranslation_Entryobjects with$entries.
- Lines 285, 295, 303, 313, 324, 327: Comparing expected
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$rolereturned from$wp_roles->get_role().
- Line 2137: Comparing
tests/phpunit/tests/user/updateUserCaches.php:- Line 15: Comparing raw database row
$raw_userdata(from$wpdb->get_row()) with cached object returned fromwp_cache_get( $u, 'users' ). - Line 69: Comparing raw database row
$raw_userdatawith cached object returned fromwp_cache_get( $u, 'users' ).
- Line 15: Comparing raw database row
All 3 calls intentionally compare object instances by value:
WP_Roleconstructor creates a fresh object instance that differs in object identity from the registered instance stored in$wp_roles.- 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 frommap_deep(). - Line 96: Comparing expected
(object)with mapped object containing an array property returned frommap_deep(). - Line 116: Comparing expected
(object)with mapped nested object returned frommap_deep(). - Line 144: Comparing expected
(object)with mapped object having properties passed by reference returned frommap_deep().
- Line 80: Comparing expected
tests/phpunit/tests/formatting/stripslashesDeep.php:- Line 48: Comparing expected
$obj_new(stdClass) with stripped object returned fromstripslashes_deep().
- Line 48: Comparing expected
All 5 calls intentionally compare object instances by value:
map_deep()andstripslashes_deep()operate recursively on object structures. When comparing the transformed output with an expected object created in the test, they represent separatestdClassinstances.- 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 comparingWP_Postobjects or arrays ofWP_Postobjects returned fromget_adjacent_post().test_get_adjacent_post_exclude_self_term(): 8 calls comparingWP_Postobjects returned fromget_adjacent_post().test_get_adjacent_post_caching(): 8 calls comparingWP_Postobjects returned fromget_adjacent_post().
All 29 calls intentionally compare WP_Post instances by value:
get_adjacent_post()queries the database and instantiates freshWP_Postobjects, which are distinct instances from the fixture references in the test.assertSame()strictly checks object identity (===), which fails when comparing distinctWP_Postinstances representing the same post.
As noted specifically by committer @lancewillett in Trac #64895 (comment:93):
"
link/getAdjacentPost.php, the largest single file, comparesWP_Postobjects, whereassertEquals()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.
@lancewillett commented on PR #13932:
6 weeks ago
#109
PR #13932 landed in https://core.trac.wordpress.org/changeset/64064
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()):
tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php:- Line 438: Converted
assertEquals( 200, $response->get_status() )toassertSame(). - Line 469: Converted
assertEquals( 404, $response->get_status() )toassertSame().
- Line 438: Converted
tests/phpunit/tests/rest-api/wpRestAbilitiesV1RunController.php:- Line 432: Converted status code / data comparison
assertEquals( 8, $response->get_data() )toassertSame(). - Line 454: Converted
assertEquals( self::$user_id, $data['id'] )toassertSame(). - Line 678: Converted status code comparison
assertEquals( 200, $response->get_status() )toassertSame(). - Line 792: Converted array comparison
assertEquals( array( 1, 2, 3 ), $data['array'] )toassertSame(). - Line 1300: Converted
assertEquals( $inputs, $data['echo'] )toassertSame(). - Lines 1349–1351: Converted string assertions for
$input['utf8'],$input['emoji'], and$input['html']toassertSame().
- Line 432: Converted status code / data comparison
Object Value Comparisons Documented:
tests/phpunit/tests/rest-api/rest-block-renderer-controller.php:- Line 383: Comparing
json_decode()stdClassinstances returned by the block type renderer against$data['rendered'].
- Line 383: Comparing
tests/phpunit/tests/rest-api/rest-users-controller.php:- Lines 1178–1179: Comparing
$data['capabilities']and$data['extra_capabilities']againstnew stdClass(). - Lines 3358–3359: Comparing
(object) $user->allcapsand(object) $user->capsagainst$data['capabilities']and$data['extra_capabilities'].
- Lines 1178–1179: Comparing
tests/phpunit/tests/rest-api/wpRestTemplatesController.php:- Line 1184: Comparing
new stdClass()with$datawhen a fallback template is not found.
- Line 1184: Comparing
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 theuserscache 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:
- The
userscache is cleared prior to callingupdate_user_caches(). - The tests genuinely verify that
update_user_caches()repopulates theuserscache bucket. - 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!
@lancewillett commented on PR #13933:
6 weeks ago
#114
PR #13933 landed in https://core.trac.wordpress.org/changeset/64065
@lancewillett commented on PR #13934:
6 weeks ago
#116
PR #13934 landed in https://core.trac.wordpress.org/changeset/64066
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 fromget_page_by_path( 'some-page' ). - Line 44: Comparing
$other_att(WP_Post) with object returned fromget_page_by_path( 'some-other-page' ).
- Line 41: Comparing
tests/phpunit/tests/post/meta.php:- Line 174: Comparing
$mobj(stdClass) with database row object returned fromget_post_meta_by_id( $mid ). - Line 181: Comparing
$mobj(stdClass) with database row object returned fromget_post_meta_by_id( $mid ).
- Line 174: Comparing
tests/phpunit/tests/post/types.php:- Line 295: Comparing
$beforelabels object (stdClass) with$afterlabels object after callingget_post_type_labels().
- Line 295: Comparing
tests/phpunit/tests/post/wpCountAttachments.php:- Line 31: Comparing
$expectedobject with cached object returned fromwp_cache_get( $cache_key, 'counts' ).
- Line 31: Comparing
All 6 calls intentionally compare object instances by value:
get_page_by_path()queries the database and instantiates aWP_Postobject, which is a separate instance from fixture references in the test.get_post_meta_by_id()constructs a database row object, distinct from the manually constructed$mobjfixture.get_post_type_labels()casts the labels array to a fresh(object), producing a distinct instance from$before.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 fromgenerate_postdata().
- Line 57: Comparing expected
tests/phpunit/tests/query/setupPostdata.php:- Line 68: Comparing
$u(WP_User) with$GLOBALS['authordata']set bysetup_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']afterwp_reset_postdata().
- Line 68: Comparing
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, orget_term()).
- 10 calls comparing
All 15 calls intentionally compare object instances by value:
generate_postdata(),setup_postdata(), andWP_Query::get_queried_object()instantiate freshWP_UserorWP_Termobject instances.- Identity assertions (
assertSame()) fail on distinct object instances withFailed 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.
@lancewillett commented on PR #13935:
6 weeks ago
#120
PR #13935 landed in https://core.trac.wordpress.org/changeset/64067
@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.
@lancewillett commented on PR #13937:
6 weeks ago
#123
PR #13937 landed in https://core.trac.wordpress.org/changeset/64068
@lancewillett commented on PR #13940:
6 weeks ago
#125
PR #13940 landed in https://core.trac.wordpress.org/changeset/64069
@lancewillett commented on PR #13936:
6 weeks ago
#127
PR #13936 landed in https://core.trac.wordpress.org/changeset/64070
@lancewillett commented on PR #13939:
6 weeks ago
#129
PR #13939 landed in https://core.trac.wordpress.org/changeset/64071
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:
tests/phpunit/tests/option/option.php(Line 160):- Compares expected
stdClasswith object returned fromget_option( $key ). In WordPress, option objects are serialized on save and unserialized on retrieval, producing a distinct object instance. Added explanatory comment.
- Compares expected
tests/phpunit/tests/option/sanitizeOption.php(Line 161):- Compares expected permalink structure sanitize result (
$expected) with$actual. On single-site installationsget_option( 'permalink_structure' )returnsfalse, while on multisite installations it returns''(empty string). RetainedassertEquals()and added an explanatory comment.
- Compares expected permalink structure sanitize result (
tests/phpunit/tests/option/siteOption.php(Line 203):- Compares expected
stdClasswith object returned fromget_site_option( $key ). Added explanatory comment.
- Compares expected
tests/phpunit/tests/option/siteTransient.php(Lines 54, 95, 125):- Line 54: Compares expected
stdClasswith transient object returned fromget_site_transient( $key ). - Lines 95, 125: Compares expected
(object) array(...)with database row object returned by$wpdb->get_row(). Added explanatory comments.
- Line 54: Compares expected
tests/phpunit/tests/option/transient.php(Line 54):- Compares expected
stdClasswith transient object returned fromget_transient( $key ). Added explanatory comment.
- Compares expected
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.
- Already documented with an existing inline comment explaining object shape comparison vs non-object
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:
- 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 bywp_upload_dir(), so strict inequality assertion is appropriate.
- Converted
- Documentation of Intentional Value Comparisons:
tests/phpunit/tests/multisite/network.php(Lines 242, 273):- Added inline comments explaining that
assertEquals()is retained becauseget_blog_count()may return a numeric string from the database/transient (e.g.'1'vs1, or'3'vs3).
- Added inline comments explaining that
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 expectedWP_Siteinstances. - Lines 602, 613: Added comments explaining that remote post objects retrieved via
get_blog_post()andget_post()are separateWP_Postinstances intentionally compared by value.
- Lines 152, 163, 164, 441: Added comments explaining that cached site objects returned from
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 fromwp_get_scheduled_event()viapre_get_scheduled_eventfilter.test_get_scheduled_event_singles(): 3 calls comparing expected one-off event objects with objects returned fromwp_get_scheduled_event().test_get_scheduled_event_recurring(): 3 calls comparing expected recurring event objects with objects returned fromwp_get_scheduled_event().
All 7 assertions compare distinct stdClass event object instances by value:
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.assertSame()strictly checks object identity (===), which fails when comparing distinctstdClassinstances 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.
@lancewillett commented on PR #13945:
5 weeks ago
#134
PR #13945 landed in https://core.trac.wordpress.org/changeset/64078
@lancewillett commented on PR #13946:
5 weeks ago
#136
PR #13946 landed in https://core.trac.wordpress.org/changeset/64079
@lancewillett commented on PR #13947:
5 weeks ago
#138
PR #13947 landed in https://core.trac.wordpress.org/changeset/64080
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.phptestcase-canonical.phpabstract-testcase.phputils.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 toassertSameSets*()assertDiscardWhitespace()accepts mixed typesgen_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 behaviorgen_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
@lancewillett commented on PR #13965:
5 weeks ago
#141
PR #13965 landed in https://core.trac.wordpress.org/changeset/64084
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 $postwith$postby value before and after the filter andget_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
DateTimeImmutableexpected value from the data provider with the object returned fromclamp( $value, $min, $max ).
- Line 197: Comparing a
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.phpassertTableRowHasValue(): Comparing a freshly built(object) array( $column => $value )expected literal with thestdClassrow 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 whyassertEquals()is retained intest_get_term_by_id()for comparingWP_Termobjects by value. - In
wpSetObjectTerms.php: Added explanatory comment intest_change_object_terms_by_name()documenting whyassertEquals()is retained when comparing term taxonomy IDs returned bywp_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 whyassertEquals()is retained when comparingDateTimeImmutableobjects 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
- Check out this branch.
- Run:
npm run test:php -- --test-suffix .php tests/phpunit/tests/db
- 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— aDateTimeImmutablefrom 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
- Check out this branch.
- Run:
npm run test:php -- --test-suffix .php tests/phpunit/tests/compat
- 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 strictassertSame(). - The remaining assertions in
cache.php,functions.php,json-schema.php,post.php,query.php,theme.php, anduser.phpintentionally compare objects by value (WP_Object_Cache,DateTime,stdClass,WP_Term,WP_Theme, or numeric string IDs from database/metadata), whereassertSame()would fail due to object identity or type juggling. These are documented with the standardKeep assertEquals()inline comment.
How?
- In
tests/phpunit/tests/functions.php:- Converted
assertEquals( WP_MAX_MEMORY_LIMIT, $ini_limit_after )toassertSame( WP_MAX_MEMORY_LIMIT, $ini_limit_after ). - Added
// Keep assertEquals() because the objects are intentionally compared by value.forDateTimecomparison inmysql_to_rfc3339tests.
- Converted
- In
tests/phpunit/tests/cache.php:- Documented
WP_Object_Cacheobject value comparison.
- Documented
- In
tests/phpunit/tests/json-schema.php:- Documented
stdClassobject value comparison in schema preparation test.
- Documented
- In
tests/phpunit/tests/post.php:- Documented
stdClassobject value comparison inwp_count_poststest.
- Documented
- In
tests/phpunit/tests/query.php:- Documented
WP_Termobject value comparisons intag_queried_objecttests.
- Documented
- In
tests/phpunit/tests/theme.php:- Documented
WP_Themeobject value comparisons intest_wp_get_themes_defaultandtest_get_themes_default.
- Documented
- 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- fromget_term( ..., ARRAY_A )(integer IDs)$result- fromwp.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.
@shailu25 commented on PR #14001:
5 weeks ago
#156
@shailu25 commented on PR #13998:
5 weeks ago
#157
@lancewillett commented on PR #13993:
5 weeks ago
#159
PR #13993 landed in https://core.trac.wordpress.org/changeset/64105
@lancewillett commented on PR #13996:
5 weeks ago
#161
PR #13996 landed in https://core.trac.wordpress.org/changeset/64106
@lancewillett commented on PR #13997:
5 weeks ago
#163
PR #13997 landed in https://core.trac.wordpress.org/changeset/64107
@lancewillett commented on PR #13998:
5 weeks ago
#165
PR #13998 landed in https://core.trac.wordpress.org/changeset/64108
@lancewillett commented on PR #14001:
5 weeks ago
#167
PR #14001 landed in https://core.trac.wordpress.org/changeset/64109
@lancewillett commented on PR #14002:
5 weeks ago
#169
PR #14002 landed in https://core.trac.wordpress.org/changeset/64110
@lancewillett commented on PR #14000:
5 weeks ago
#171
PR #14000 landed in https://core.trac.wordpress.org/changeset/64111
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?
- Cast expected
object_idandmenu_item_parentto(string)before comparing withassertSame(). - Normalize
object_idin the save/update fixtures the same way before the property loops. - Leave documented object-value comparisons in
nav-menu-setting.phpandwidgets.phpasassertEquals().
Testing Instructions
npm run test:php -- --group customizenpm run test:php -- --filter Tests_Customize_Nav_Menu_Item_Setting
Use of AI Tools
- Cursor
@lancewillett commented on PR #14066:
4 weeks ago
#174
PR #14066 landed in https://core.trac.wordpress.org/changeset/64263
#175
in reply to: ↑ 93
@
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_postsfilter.
- Lines 100 and 183: Documented object comparisons for
- In
tests/phpunit/tests/post/wpCountAttachments.php:- Line 198: Documented array containing the filtered counts object passed to the
wp_count_attachmentsfilter. - Line 228: Documented object comparison for the
image/jpegcount object.
- Line 198: Documented array containing the filtered counts object passed to the
- In
tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-html.php:- Line 781: Documented object comparison for
json_decode()state marker object.
- Line 781: Documented object comparison for
#177
@
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.phptest_query_var_cache_should_be_bust_when_comment_is_added():assertNotEquals→assertNotSame
tests/phpunit/tests/comment/query.phptest_cache_should_be_sensitive_to_parent__in():assertNotEquals→assertNotSametest_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
- Start the local WordPress develop environment.
- 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
- Pagination test:
tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php- Pagination test:
assertNotEquals( $page1_names, $page2_names )→assertNotSame
- Pagination test:
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()toassertNotSame() - Leave other assertions in
rest-api/unchanged
Testing instructions
- Start the local WordPress develop environment.
- 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.phptest_key(): 3assertNotEquals→assertNotSameforTranslation_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()toassertNotSame() - Leave documented object-value
assertEquals()calls in the directory unchanged
Testing instructions
- Start the local WordPress develop environment.
- Run:
npm run test:php -- --test-suffix .php tests/phpunit/tests/pomo/
Use of AI tools
Cursor
#181
@
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 shapeassertEquals( (object) array( 'publish' => 5 ), $stored_counts )— object value comparisonassertEquals( 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 addedtests/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→assertNotSametest_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()toassertNotSame() - Leave other assertions in the file unchanged
Testing instructions
- Start the local WordPress develop environment.
- Run:
npm run test:php -- --filter Tests_AdminBar - 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()toassertNotSame() - Leave other assertions in the file unchanged
Testing instructions
- Start the local WordPress develop environment.
- 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→assertNotSameforuser_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()toassertNotSame() - Leave other assertions in the file unchanged
Testing instructions
- Start the local WordPress develop environment.
- 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: ReplaceassertNotEquals()withassertNotSame()for scalar comparisons
How to test
- Run the affected test class:
phpunit tests/phpunit/tests/file.php - 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: ReplaceassertNotEquals()withassertNotSame()for scalar comparisons
How to test
- Run the affected test class:
phpunit tests/phpunit/tests/link.php - 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>
@SergeyBiryukov commented on PR #14868:
2 weeks ago
#192
Thanks for the PR! Merged in r64773.
@lancewillett commented on PR #14727:
2 weeks ago
#194
PR #14727 landed in https://core.trac.wordpress.org/changeset/64778
@lancewillett commented on PR #14728:
2 weeks ago
#196
PR #14728 landed in https://core.trac.wordpress.org/changeset/64779
@lancewillett commented on PR #14729:
2 weeks ago
#198
PR #14729 landed in https://core.trac.wordpress.org/changeset/64780
@lancewillett commented on PR #14853:
2 weeks ago
#200
PR #14853 landed in https://core.trac.wordpress.org/changeset/64781
@lancewillett commented on PR #14855:
2 weeks ago
#203
PR #14855 landed in https://core.trac.wordpress.org/changeset/64782
@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: ReplaceassertNotEquals()withassertNotSame()
How to test
- Run:
phpunit --group customize --filter test_filter_dynamic_sidebar_paramsor:phpunit tests/phpunit/tests/customize/widgets.php - 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 replacementstests/phpunit/tests/term/getTerms.php: 2 replacementstests/phpunit/tests/term/wpInsertTerm.php: 2 replacementstests/phpunit/tests/term/cache.php: 1 replacementtests/phpunit/tests/term/wpUpdateTerm.php: 1 replacement
Testing Instructions
- Run:
phpunit tests/phpunit/tests/term/ - 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 replacementstests/phpunit/tests/query/cacheResults.php: 1 replacement
Testing Instructions
- Run:
phpunit tests/phpunit/tests/query/ - 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
- Run:
phpunit tests/phpunit/tests/link/ - 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 replacementstests/phpunit/tests/db.php: 2 replacementstests/phpunit/tests/widgets.php: 1 replacementtests/phpunit/tests/rewrite.php: 1 replacement
Testing Instructions
- Run:
phpunit tests/phpunit/tests/post.phpphpunit tests/phpunit/tests/db.phpphpunit tests/phpunit/tests/widgets.phpphpunit tests/phpunit/tests/rewrite.php
- All tests should pass
Use of AI Tools
- Cursor
@lancewillett commented on PR #14975:
2 weeks ago
#211
PR #14975 landed in https://core.trac.wordpress.org/changeset/64804
@lancewillett commented on PR #14976:
2 weeks ago
#213
PR #14976 landed in https://core.trac.wordpress.org/changeset/64805
@lancewillett commented on PR #14978:
2 weeks ago
#215
PR #14978 landed in https://core.trac.wordpress.org/changeset/64806
@lancewillett commented on PR #14979:
2 weeks ago
#217
PR #14979 landed in https://core.trac.wordpress.org/changeset/64807
@lancewillett commented on PR #14982:
2 weeks ago
#219
PR #14982 landed in https://core.trac.wordpress.org/changeset/64808
@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>
@lancewillett commented on PR #14857:
2 weeks ago
#226
PR #14857 landed in https://core.trac.wordpress.org/changeset/64825
@lancewillett commented on PR #14709:
2 weeks ago
#228
PR #14709 landed in https://core.trac.wordpress.org/changeset/64826
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.phptests/phpunit/tests/admin/includes/plugin/wpCleanPluginsCache.php
No assertion logic was changed.
Testing Instructions
- Check out this branch on current
trunk. - 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
@lancewillett commented on PR #15209:
11 days ago
#231
PR #15209 landed in https://core.trac.wordpress.org/changeset/65079
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!
@lancewillett commented on PR #15332:
8 days ago
#235
PR #15332 landed in https://core.trac.wordpress.org/changeset/65185
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
## PR Description
assertSame()instead ofassertEquals()to enforce strict type comparisons.(int)cast forpost_authorin the bulk edit test to avoid false positives due to string/integer mismatches.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 withassertSame().