Skip to content

Commit 875afc7

Browse files
committed
Use assertSame, add messages.
1 parent d734ac4 commit 875afc7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,19 +4176,20 @@ public function test_get_items_type_arg_authenticated( $comment_type, $count ) {
41764176
$request->set_param( 'per_page', self::$per_page );
41774177

41784178
$response = rest_get_server()->dispatch( $request );
4179-
$this->assertEquals( 200, $response->get_status() );
4179+
$this->assertSame( 200, $response->get_status(), 'Comments endpoint is expected to return a 200 status' );
41804180

4181-
$comments = $response->get_data();
4182-
$this->assertCount( 'comment' === $comment_type ? $count + self::$total_comments : $count, $comments );
4181+
$comments = $response->get_data();
4182+
$expected_count = 'comment' === $comment_type ? $count + self::$total_comments : $count;
4183+
$this->assertCount( $expected_count, $comments, "comment type '{$comment_type}' is expect to have {$expected_count} comments" );
41834184

41844185
// Next, test getting the individual comments.
41854186
foreach ( $comments as $comment ) {
41864187
$request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment['id'] ) );
41874188
$response = rest_get_server()->dispatch( $request );
41884189

4189-
$this->assertEquals( 200, $response->get_status() );
4190+
$this->assertSame( 200, $response->get_status(), 'Individual comment endpoint is expected to return a 200 status' );
41904191
$data = $response->get_data();
4191-
$this->assertEquals( $comment_type, $data['type'] );
4192+
$this->assertSame( $comment_type, $data['type'], "Individual comment is expected to have type '{$comment_type}'" );
41924193
}
41934194
}
41944195

@@ -4228,9 +4229,10 @@ public function test_get_items_type_arg_unauthenticated( $comment_type, $count )
42284229
$response = rest_get_server()->dispatch( $request );
42294230

42304231
// Only comments can be retrieved from the /comments (multiple) endpoint when unauthenticated.
4231-
$this->assertEquals( 'comment' === $comment_type ? 200 : 401, $response->get_status() );
4232+
$expected_status = 'comment' === $comment_type ? 200 : 401;
4233+
$this->assertSame( $expected_status, $response->get_status(), 'Comments endpoint did not return the expected status' );
42324234
if ( 'comment' !== $comment_type ) {
4233-
$this->assertErrorResponse( 'rest_forbidden_param', $response, 401 );
4235+
$this->assertErrorResponse( 'rest_forbidden_param', $response, 401, 'Comments endpoint did not return the expected error response for forbidden parameters' );
42344236
}
42354237

42364238
// Individual comments.
@@ -4241,7 +4243,7 @@ public function test_get_items_type_arg_unauthenticated( $comment_type, $count )
42414243
// Individual comments using the /comments/<id> endpoint can (unexpectedly) be
42424244
// retrieved by unauthenticated users - except for the 'note' type which is restricted.
42434245
// See https://core.trac.wordpress.org/ticket/44157.
4244-
$this->assertEquals( 'note' === $comment_type ? 401 : 200, $response->get_status() );
4246+
$this->assertSame( 'note' === $comment_type ? 401 : 200, $response->get_status(), 'Individual comment endpoint did not return the expected status' );
42454247
}
42464248
}
42474249
}

0 commit comments

Comments
 (0)