Skip to content

Tests: Add unit coverage for rest_are_values_equal() - #15285

Closed
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-are-values-equal-65819
Closed

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/rest-are-values-equal-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for rest_are_values_equal(), covering scalar equality, int/float coercion, nested arrays, object key order, and unequal values.

Test-only; no production code changes.

Why

rest_are_values_equal() had no direct @covers coverage. Small helper coverage fits the #65819 test cleanup track.

How

Add tests/phpunit/tests/rest-api/restAreValuesEqual.php with @covers ::rest_are_values_equal.

  • Equal scalars, nulls, lists, and objects (including different key order)
  • Int/float values compare equal when numerically the same
  • Unequal strings, types, list order, counts, missing keys, and nested mismatches return false

Testing Instructions

  1. npm run test:php -- --filter Tests_REST_API_RestAreValuesEqual
  2. npm run test:php -- --filter Tests_REST_API_RestAreValuesEqual -c tests/phpunit/multisite.xml
  3. npm run test:php -- --filter Tests_REST_API_RestAreValuesEqual --order-by=random
  4. npm run test:php -- --group restapi

Use of AI Tools

  • Cursor

Add unit tests for JSON Schema value equality across scalars, int/float coercion, and arrays.

See #65819.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The equality tests miss unequal integer–float pairs, matching null-valued properties, and nested coercion or reordered keys, leaving REST enum regressions undetected.

3 open issues
What changed in this PR

Adds direct PHPUnit coverage for the REST API equality helper rest_are_values_equal(), supporting the test cleanup work in Trac #65819. No production code changes.

Changes:

  • Adds a dedicated test class with @covers metadata and the restapi group.
  • Tests scalar equality, numeric coercion, array ordering, nested values, and unequal inputs through data providers.
File Description
tests/​phpunit/​tests/​rest-api/​restAreValuesEqual.php Adds data-driven tests for equal and unequal REST values.

Review effort: Balanced

Add null object properties, nested int/float coercion with reordered keys, and unequal mixed-number cases. Align data provider arrows for PHPCS.

See #65819.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for this test-only change.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 31, 2026 17:23
@github-actions

Copy link
Copy Markdown

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:

Props shailu25.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct comparator checks include meaningful nested numeric coercion, reordered keys, and null-valued properties. Existing schema tests overlap scalar/list cases but do not justify rejecting the whole patch.

Local randomized single-site and multisite checks passed alongside related existing tests; PHPCS passed.

Optional: Trim 18 rows to distinct outcomes, especially repeated scalar identity cases. Keep null-valued keys and nested coercion; no extra edge matrix.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Verify nested REST value comparisons and request argument validation before sanitization, including numeric coercion and invalid-type errors.

Developed in: #15285, #15292

Props shailu25.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@65141 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Verify nested REST value comparisons and request argument validation before sanitization, including numeric coercion and invalid-type errors.

Developed in: WordPress/wordpress-develop#15285, WordPress/wordpress-develop#15292

Props shailu25.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@65141


git-svn-id: http://core.svn.wordpress.org/trunk@64290 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants