Skip to content

Tests: Add unit coverage for rest_parse_request_arg() - #15292

Draft
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/rest-parse-request-arg-65819
Draft

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/rest-parse-request-arg-65819

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Adds a dedicated PHPUnit class for rest_parse_request_arg(), covering validate-then-sanitize success paths and invalid-value WP_Error returns.

Test-only; no production code changes.

Why

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

How

Add tests/phpunit/tests/rest-api/restParseRequestArg.php with @covers ::rest_parse_request_arg.

  • Returns sanitized values for valid integer and boolean inputs
  • Returns a rest_invalid_type error for invalid values

Testing Instructions

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

Use of AI Tools

  • Cursor

Add unit tests for validate-then-sanitize parsing of REST request args, including invalid values.

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 reported for the added REST request argument parsing tests.

No open issues 🎉

What changed in this PR

Adds dedicated PHPUnit coverage for rest_parse_request_arg() as part of the REST API test cleanup tracked in #65819. No production code changes are included.

Changes:

  • Adds a test class with an explicit @covers annotation.
  • Checks integer and boolean sanitization for valid inputs.
  • Checks that invalid integer input returns a WP_Error with code rest_invalid_type.
File Description
tests/​phpunit/​tests/​rest-api/​restParseRequestArg.php Adds direct tests for valid-value sanitization and invalid-value error handling.

Review effort: Balanced

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.

2 participants