From 25b9f8b15608d63104405934d91e7a11eb8f2205 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 23 Apr 2024 18:55:26 +0000 Subject: [PATCH] Tests: Add a `$message` parameter for a custom assertion in `WP_Test_REST_TestCase`. All assertions in PHPUnit have a `$message` parameter. Setting this parameter allows to distinguish which assertion is failing when a test runs multiple assertions, making debugging of the tests easier. This optional parameter is now added for `WP_Test_REST_TestCase::assertErrorResponse()`. Follow-up to [34928], [51478]. Props mykolashlyakhtun, antonvlasenko, swissspidy, SergeyBiryukov. Fixes #60426. git-svn-id: https://develop.svn.wordpress.org/trunk@58039 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase-rest-api.php | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/includes/testcase-rest-api.php b/tests/phpunit/includes/testcase-rest-api.php index 54644f13fb..778596e974 100644 --- a/tests/phpunit/includes/testcase-rest-api.php +++ b/tests/phpunit/includes/testcase-rest-api.php @@ -1,19 +1,31 @@ as_error(); } - $this->assertWPError( $response ); - $this->assertSame( $code, $response->get_error_code() ); + $this->assertWPError( $response, $message ); + $this->assertSame( $code, $response->get_error_code(), $message ); if ( null !== $status ) { $data = $response->get_error_data(); - $this->assertArrayHasKey( 'status', $data ); - $this->assertSame( $status, $data['status'] ); + $this->assertArrayHasKey( 'status', $data, $message ); + $this->assertSame( $status, $data['status'], $message ); } } }