Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-09-02 00:35:36 +00:00
parent ba7c6a2d5f
commit 164b22cf6a
426 changed files with 7959 additions and 7949 deletions

View File

@@ -26,13 +26,13 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
}
public function test_validate_within_min_max_range_min_exclusive() {
@@ -51,9 +51,9 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 3, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 9, $request, 'minmaxrange' );
@@ -61,7 +61,7 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
$ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
}
public function test_validate_within_min_max_range_max_exclusive() {
@@ -80,7 +80,7 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 3, $request, 'minmaxrange' );
@@ -88,9 +88,9 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
$ret = rest_validate_request_arg( 9, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
}
public function test_validate_within_min_max_range_both_exclusive() {
@@ -110,17 +110,17 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 3, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 9, $request, 'minmaxrange' );
$this->assertTrue( $ret );
$ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
}
public function test_validate_greater_than_min_inclusive() {
@@ -137,7 +137,7 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
$this->assertEquals( 'greaterthanmin must be greater than or equal to 2', $ret->get_error_message() );
$this->assertSame( 'greaterthanmin must be greater than or equal to 2', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
$this->assertTrue( $ret );
}
@@ -157,9 +157,9 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
$this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
$this->assertSame( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
$this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
$this->assertSame( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
$ret = rest_validate_request_arg( 3, $request, 'greaterthanmin' );
$this->assertTrue( $ret );
}
@@ -178,7 +178,7 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
$this->assertEquals( 'lessthanmax must be less than or equal to 10', $ret->get_error_message() );
$this->assertSame( 'lessthanmax must be less than or equal to 10', $ret->get_error_message() );
$ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
$this->assertTrue( $ret );
}
@@ -198,9 +198,9 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
)
);
$ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
$this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() );
$this->assertSame( 'lessthanmax must be less than 10', $ret->get_error_message() );
$ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
$this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() );
$this->assertSame( 'lessthanmax must be less than 10', $ret->get_error_message() );
$ret = rest_validate_request_arg( 9, $request, 'lessthanmax' );
$this->assertTrue( $ret );
}