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

@@ -96,7 +96,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_after_array() {
@@ -141,7 +141,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_after_string() {
@@ -159,7 +159,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_after_string_inclusive() {
@@ -178,7 +178,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
}
/**
@@ -207,7 +207,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
}
/**
@@ -247,8 +247,8 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2 ), $before_posts );
$this->assertEquals( array( $p1 ), $after_posts );
$this->assertSame( array( $p2 ), $before_posts );
$this->assertSame( array( $p1 ), $after_posts );
}
/**
@@ -331,8 +331,8 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2 ), $before_posts );
$this->assertEquals( array( $p1 ), $after_posts );
$this->assertSame( array( $p2 ), $before_posts );
$this->assertSame( array( $p1 ), $after_posts );
}
/**
@@ -415,8 +415,8 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2 ), $before_posts );
$this->assertEquals( array( $p1 ), $after_posts );
$this->assertSame( array( $p2 ), $before_posts );
$this->assertSame( array( $p1 ), $after_posts );
}
/**
@@ -499,8 +499,8 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2 ), $before_posts );
$this->assertEquals( array( $p1 ), $after_posts );
$this->assertSame( array( $p2 ), $before_posts );
$this->assertSame( array( $p1 ), $after_posts );
}
/**
@@ -583,8 +583,8 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2 ), $before_posts );
$this->assertEquals( array( $p1 ), $after_posts );
$this->assertSame( array( $p2 ), $before_posts );
$this->assertSame( array( $p1 ), $after_posts );
}
/**
@@ -667,7 +667,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1, $p2 ), $before_posts );
$this->assertSame( array( $p1, $p2 ), $before_posts );
}
public function test_date_query_year() {
@@ -683,7 +683,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_month() {
@@ -699,7 +699,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_week() {
@@ -715,7 +715,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_day() {
@@ -732,7 +732,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_dayofweek() {
@@ -749,7 +749,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
/**
@@ -769,7 +769,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_hour() {
@@ -786,7 +786,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
/**
@@ -806,7 +806,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_minute() {
@@ -823,7 +823,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_second() {
@@ -840,7 +840,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_between_two_times() {
@@ -889,7 +889,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1, $p3 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1, $p3 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_query_compare_greater_than_or_equal_to() {
@@ -910,7 +910,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
}
public function test_date_params_monthnum_m_duplicate() {
@@ -929,7 +929,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertContains( "MONTH( $wpdb->posts.post_date ) = 5", $this->q->request );
$this->assertNotContains( "MONTH( $wpdb->posts.post_date ) = 9", $this->q->request );
@@ -951,7 +951,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertContains( "WEEK( $wpdb->posts.post_date, 1 ) = 43", $this->q->request );
$this->assertNotContains( "WEEK( $wpdb->posts.post_date, 1 ) = 42", $this->q->request );
@@ -992,7 +992,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
_unregister_taxonomy( 'foo' );
$this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
}
/**
@@ -1023,7 +1023,7 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
)
);
$this->assertEquals( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
$this->assertSame( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
}
/**