Skip to content

Tests: Use assertWPError() in REST API tests - #14563

Closed
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/65819-assert-wp-error-rest-api
Closed

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/65819-assert-wp-error-rest-api

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac ticket: #65819

Replaces a generic assertInstanceOf( 'WP_Error', … ) assertion in tests/phpunit/tests/rest-api.php with WordPress’s dedicated assertWPError() assertion.

Test-only change.

Why

Dedicated assertion methods improve failure reporting by including the WP_Error code and message automatically.

How

  • Swap one assertInstanceOf( 'WP_Error', … ) call for assertWPError() in rest_ensure_response() coverage

Testing instructions

npm run test:php -- --filter Tests_REST_API::test_rest_ensure_response_accepts_wp_error_and_returns_wp_error

Use of AI Tools

  • Cursor

@shail-mehta
shail-mehta requested a balanced review from Copilot October 20, 2026 16:46

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

The helper preserves the existing assertion behavior, with no unresolved issues.

No open issues 🎉

What changed in this PR

Updates one REST API test to use WordPress’s dedicated error assertion without changing production code.

Changes:

  • Replaces assertInstanceOf( 'WP_Error', … ) with assertWPError() in rest_ensure_response() coverage.
File Description
tests/​phpunit/​tests/​rest-api.php Uses the dedicated assertion for a WP_Error response.

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 20, 2026 17:05
@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. You can also manually ask me to refresh this list by adding the props-bot label.

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.

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

The test-only substitution preserves assertion behavior and has no unresolved findings.

No open issues 🎉

Review effort: Balanced

@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.

Reviewed with the unit-tests audit: the inherited assertWPError() helper delegates to the same type assertion, preserving the existing error-code checks and custom messages.

The affected class passed in three randomized single-site and three randomized multisite runs (seeds 14557, 14561, and 14568); every changed test executed. PHPCS passed, CI is green, and Copilot reviewed this head without findings.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 20, 2026
Use the dedicated assertion helper for expected `WP_Error` results, preserving the existing test behavior and assertion messages.

Developed in: #14563

Props shailu25.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64645 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 20, 2026
Use the dedicated assertion helper for expected `WP_Error` results, preserving the existing test behavior and assertion messages.

Developed in: WordPress/wordpress-develop#14563

Props shailu25.
See #65819.

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


git-svn-id: http://core.svn.wordpress.org/trunk@63795 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@shail-mehta
shail-mehta deleted the tests/65819-assert-wp-error-rest-api branch October 21, 2026 09:05
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