Tests: Use strict assertions and document value comparisons in REST API tests - #13936
noruzzamans wants to merge 4 commits into
Conversation
…PI tests. See #64895.
|
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. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The assertion changes match the tested value types, and the retained loose comparisons are appropriately documented.
Review effort: Balanced
Findings: None
What changed in this PR
Updates REST API tests for stricter comparisons and clarifies intentional object-value assertions.
Changes:
- Replaces 10 loose assertions with
assertSame(). - Documents six intentional object-value comparisons using
assertEquals().
| File | Description |
|---|---|
rest-block-renderer-controller.php |
Documents an object-value comparison. |
rest-users-controller.php |
Documents capability object comparisons. |
wpRestAbilitiesV1ListController.php |
Uses strict status-code assertions. |
wpRestAbilitiesV1RunController.php |
Uses strict response and input assertions. |
wpRestTemplatesController.php |
Documents the empty-object comparison. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
lancewillett
left a comment
There was a problem hiding this comment.
One assertion needs adjustment before landing. Applying this patch to current trunk produces the same calculator test failure in both single-site and multisite runs; the baseline passes. The other changed assertions passed.
AI review · gpt-6
|
|
||
| $this->assertSame( 200, $response->get_status() ); | ||
| $this->assertEquals( 8, $response->get_data() ); | ||
| $this->assertSame( 8, $response->get_data() ); |
There was a problem hiding this comment.
This strict comparison fails on current trunk: Failed asserting that 8.0 is identical to 8. I reproduced it in both single-site and multisite runs.
The calculator declares its inputs as number. REST sanitizes those values to floats before the callback adds them, so the result is 8.0. See the number sanitizer.
Could you retain the numeric value comparison here, with a short explanation? The schema permits both integers and floats. If this test is intended to verify float normalization specifically, use an explicit float expectation and document that intent. Please recheck against current trunk.
AI review · gpt-6
|
Updated! The All 47 tests and 217 assertions pass in both single-site and multisite runs. |
|
PR #13936 landed in https://core.trac.wordpress.org/changeset/64070 |
Use `assertSame()` for status codes, numeric results, arrays, and strings in the Abilities API tests. Expect the calculator result as a float because its `number` inputs are normalized to floats. Document why comparisons of separate objects retain `assertEquals()` in the block renderer, users, and templates tests. Developed in: #13936 Props noruzzaman. See #64895. git-svn-id: https://develop.svn.wordpress.org/trunk@64070 602fd350-edb4-49c9-b593-d223f7449a82
Use `assertSame()` for status codes, numeric results, arrays, and strings in the Abilities API tests. Expect the calculator result as a float because its `number` inputs are normalized to floats. Document why comparisons of separate objects retain `assertEquals()` in the block renderer, users, and templates tests. Developed in: WordPress/wordpress-develop#13936 Props noruzzaman. See #64895. Built from https://develop.svn.wordpress.org/trunk@64070 git-svn-id: http://core.svn.wordpress.org/trunk@63229 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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:assertEquals( 200, $response->get_status() )toassertSame().assertEquals( 404, $response->get_status() )toassertSame().tests/phpunit/tests/rest-api/wpRestAbilitiesV1RunController.php:assertEquals( 8, $response->get_data() )toassertSame().assertEquals( self::$user_id, $data['id'] )toassertSame().assertEquals( 200, $response->get_status() )toassertSame().assertEquals( array( 1, 2, 3 ), $data['array'] )toassertSame().assertEquals( $inputs, $data['echo'] )toassertSame().$input['utf8'],$input['emoji'], and$input['html']toassertSame().Object Value Comparisons Documented:
tests/phpunit/tests/rest-api/rest-block-renderer-controller.php:json_decode()stdClassinstances returned by the block type renderer against$data['rendered'].tests/phpunit/tests/rest-api/rest-users-controller.php:$data['capabilities']and$data['extra_capabilities']againstnew stdClass().(object) $user->allcapsand(object) $user->capsagainst$data['capabilities']and$data['extra_capabilities'].tests/phpunit/tests/rest-api/wpRestTemplatesController.php:new stdClass()with$datawhen a fallback template is not found.In accordance with maintainer guidance on Trac #64895, scalar/integer/array assertions are converted to
assertSame(), and intentional object-value comparisons are preserved and documented with:// Keep assertEquals() because the objects are intentionally compared by value.Testing Instructions
Trac ticket: https://core.trac.wordpress.org/ticket/64895
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 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.