Repository navigation
Conversation
Replace `assertEquals()`/`assertNotEquals()` with `assertSame()`/`assertNotSame()` across several test files. Strict assertions also verify the value type, catching unintended type coercion. For assertions comparing values that may differ in type (e.g. `ceil()` returning a float), the loose comparison is intentionally retained.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
This PR updates multiple WordPress Core PHPUnit tests to use strict PHPUnit assertions, improving type-safety in comparisons and making expected return types/values more explicit in the test suite.
Changes:
- Replaced
assertEquals()withassertSame()in several tests where identical type/value matches are expected. - Replaced
assertNotEquals()withassertNotSame()in several tests where non-identical comparisons are expected. - Applied these changes across Theme, Term, Template, Script Modules, REST API, Posts, Images, Icons, and Customizer test coverage.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/phpunit/tests/theme/themeDir.php | Uses strict non-identity assertion when verifying theme directory paths don’t end with /. |
| tests/phpunit/tests/term/wpInsertTerm.php | Uses strict non-identity assertion to ensure distinct term IDs are created. |
| tests/phpunit/tests/template.php | Uses strict non-identity assertion to ensure processed output differs from original output. |
| tests/phpunit/tests/script-modules/wpScriptModules.php | Uses strict array identity assertion for the expected import map structure/types. |
| tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php | Uses strict assertion for total-count REST header after integer casting. |
| tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php | Uses strict assertion for total-count REST header after integer casting. |
| tests/phpunit/tests/rest-api/rest-users-controller.php | Uses strict non-identity assertions for role checks in REST user update tests. |
| tests/phpunit/tests/post.php | Uses strict non-identity assertions for post status checks in count invalidation tests. |
| tests/phpunit/tests/image/functions.php | Uses strict non-identity assertions to ensure PDF previews don’t overwrite existing files. |
| tests/phpunit/tests/icons/wpRestIconsController.php | Uses strict assertion for expected icon names returned from REST search. |
| tests/phpunit/tests/functions.php | Uses strict non-identity assertion for default extension negative-case expectations. |
| tests/phpunit/tests/customize/setting.php | Uses strict non-identity assertions when verifying Customizer setting value transitions. |
| tests/phpunit/tests/customize/manager.php | Uses strict non-identity assertion ensuring unsafe referer URLs are not returned. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace loose equality and inequality assertions in selected core tests with strict comparisons where the fixtures and surrounding assertions establish the expected types. Developed in: #12583 Props soean, mukesh27, desrosj. See #64895. git-svn-id: https://develop.svn.wordpress.org/trunk@63880 602fd350-edb4-49c9-b593-d223f7449a82
Replace loose equality and inequality assertions in selected core tests with strict comparisons where the fixtures and surrounding assertions establish the expected types. Developed in: WordPress/wordpress-develop#12583 Props soean, mukesh27, desrosj. See #64895. Built from https://develop.svn.wordpress.org/trunk@63880 git-svn-id: http://core.svn.wordpress.org/trunk@63052 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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 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.