Make WordPress Core

Opened 2 months ago

Last modified 7 weeks ago

#60426 new enhancement

Update WP_Test_REST_TestCase::assertErrorResponse() to allow custom failure messages

Reported by: antonvlasenko's profile antonvlasenko Owned by:
Milestone: Awaiting Review Priority: normal
Severity: trivial Version:
Component: REST API Keywords: needs-patch
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 (1)

#1 @antonvlasenko
7 weeks ago

  • Severity changed from normal to trivial
Note: See TracTickets for help on using tickets.