Repository navigation
Tests: Use strict assertions or document intentional assertEquals() in new admin tests - #15891
shail-mehta wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Two test comments incorrectly describe sanitized integer fields as numeric strings, unjustifiably retaining loose comparisons instead of using assertSame().
2 open issues
What changed in this PR
Strengthens WordPress PHPUnit tests for Trac #64895 by using strict assertions where types should match and documenting retained loose comparisons. No production code changes.
Changes:
- Converts 10 color-scheme picker assertions and one PHP annotation assertion to
assertSame(). - Adds comments explaining retained
assertEquals()calls in attachment, screen-option, and translation-update tests.
| File | Description |
|---|---|
tests/phpunit/tests/functions/wpGetUpdatePhpAnnotation.php |
Strictly checks the empty-string result. |
tests/phpunit/tests/admin/includesUpdate.php |
Adds comments explaining object comparisons by value. |
tests/phpunit/tests/admin/includes/misc/setScreenOptions.php |
Adds comments explaining loose metadata comparisons. |
tests/phpunit/tests/admin/includes/misc/adminColorSchemePicker.php |
Uses strict assertions for ordering and rendered output. |
tests/phpunit/tests/admin/includes/ajax-actions/sendAttachmentToEditor.php |
Adds a comment explaining the retained parent-ID comparison. |
tests/phpunit/tests/admin/includes/ajax-actions/saveAttachmentOrder.php |
Adds a comment explaining retained menu-order comparisons. |
Review effort: Balanced
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|

Trac Ticket: #64895
What?
Converts same-type
assertEquals()calls toassertSame()in newer admin/color-scheme and update PHP annotation tests, and documents the remaining intentional loose comparisons (DB numeric strings, POST/user-meta type mismatches, and object value comparisons).Why?
assertEquals()does not compare types, so it can hide regressions that change a return value’s type, especially falsy values. On #64895, Lance noted looseassertEquals()usage rose from 165 to 183, mostly from new tests. Done looks like eitherassertSame(), or a short comment explaining whyassertEquals()is kept.How?
adminColorSchemePicker.php: 10 same-type assertions →assertSame()(string/int/array comparisons).wpGetUpdatePhpAnnotation.php: empty-string assertion →assertSame().saveAttachmentOrder.php/sendAttachmentToEditor.php: keepassertEquals()with comments (menu_order/post_parentare numeric strings from the DB).setScreenOptions.php: keepassertEquals()with comments (integer expectations vs string meta/POST values).includesUpdate.php: keepassertEquals()with comments (translation update objects compared by value).Testing Instructions
Use of AI tools