#60426 closed enhancement (fixed)
Update WP_Test_REST_TestCase::assertErrorResponse() to allow custom failure messages
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.6 | Priority: | normal |
| Severity: | trivial | Version: | |
| Component: | Build/Test Tools | Keywords: | good-first-bug has-patch has-unit-tests |
| Focuses: | coding-standards | Cc: |
Description
According to the WordPress coding standards, it is recommended that if there are more than 2 assertions in a single test method, these assertions should include custom failure messages to explain the nature of any failed assertions.
However, in the current state of the WP_Test_REST_TestCase::assertErrorResponse() helper method, it contains 2 assertions, making it impossible to add a custom message explaining the error.
To align with coding standards and improve the clarity of test failures, I propose updating the method's signature as follows:
protected function assertErrorResponse($code, $response, $status = null, $failure_message)
This change will allow developers to include a custom message when using the WP_Test_REST_TestCase::assertErrorResponse() method, improving the ability to diagnose issues during testing.
Furthermore, all the instances where this method is being used across the codebase need to be refactored to include the new $failure_message parameter, ensuring consistency.
Change History (8)
This ticket was mentioned in PR #6404 on WordPress/wordpress-develop by mykola.
2 years ago
#4
- Keywords has-patch has-unit-tests added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/60426
@SergeyBiryukov commented on PR #6404:
2 years ago
#7
Thanks for the PR! Merged in r58039.
This is best done on an ad-hoc basis when touching those tests anyway.