Tests: Use assertSame() in some newly introduced 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.

Follow-up to [49904], [49925], [49992], [50012], [50013], [50065], [50075], [50131], [50150], [50157].

See #38266, #52482.

git-svn-id: https://develop.svn.wordpress.org/trunk@50284 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-02-10 13:24:24 +00:00
parent 62d5c54b67
commit 3d259c2b22
12 changed files with 70 additions and 70 deletions

View File

@@ -1411,7 +1411,7 @@ class Tests_Post extends WP_UnitTestCase {
);
$post = get_post( $post_id );
$this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
$this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
$post_id = self::factory()->post->create(
array(
@@ -1421,7 +1421,7 @@ class Tests_Post extends WP_UnitTestCase {
);
$post = get_post( $post_id );
$this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
$this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
// Empty post_date_gmt without floating status
$post_id = self::factory()->post->create(
@@ -1450,8 +1450,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( get_date_from_gmt( $post_date_gmt ), $post->post_date );
$this->assertEquals( $post_date_gmt, $post->post_date_gmt );
$this->assertSame( get_date_from_gmt( $post_date_gmt ), $post->post_date );
$this->assertSame( $post_date_gmt, $post->post_date_gmt );
// Invalid post_date_gmt
$post_id = self::factory()->post->create(
@@ -1460,8 +1460,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( '1970-01-01 00:00:00', $post->post_date );
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
$this->assertSame( '1970-01-01 00:00:00', $post->post_date );
$this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
}
/**
@@ -1480,8 +1480,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( $post_date, $post->post_date );
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
$this->assertSame( $post_date, $post->post_date );
$this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
$post_id = self::factory()->post->create(
array(
@@ -1491,8 +1491,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( $post_date, $post->post_date );
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
$this->assertSame( $post_date, $post->post_date );
$this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
// Empty post_date_gmt without floating status
$post_id = self::factory()->post->create(
@@ -1502,8 +1502,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( $post_date, $post->post_date );
$this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt );
$this->assertSame( $post_date, $post->post_date );
$this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
$post_id = self::factory()->post->create(
array(
@@ -1513,8 +1513,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( $post_date, $post->post_date );
$this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt );
$this->assertSame( $post_date, $post->post_date );
$this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
// Valid post_date_gmt
$post_id = self::factory()->post->create(
@@ -1524,8 +1524,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( $post_date, $post->post_date );
$this->assertEquals( $post_date_gmt, $post->post_date_gmt );
$this->assertSame( $post_date, $post->post_date );
$this->assertSame( $post_date_gmt, $post->post_date_gmt );
// Invalid post_date_gmt
$post_id = self::factory()->post->create(
@@ -1535,8 +1535,8 @@ class Tests_Post extends WP_UnitTestCase {
)
);
$post = get_post( $post_id );
$this->assertEquals( $post_date, $post->post_date );
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
$this->assertSame( $post_date, $post->post_date );
$this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
}
/**
@@ -1554,7 +1554,7 @@ class Tests_Post extends WP_UnitTestCase {
'post_status' => 'draft',
)
);
$this->assertEquals( 0, $post_id );
$this->assertSame( 0, $post_id );
$post_id = self::factory()->post->create(
array(
@@ -1563,7 +1563,7 @@ class Tests_Post extends WP_UnitTestCase {
'post_status' => 'draft',
)
);
$this->assertEquals( 0, $post_id );
$this->assertSame( 0, $post_id );
// Empty post_date_gmt without floating status
$post_id = self::factory()->post->create(
@@ -1572,7 +1572,7 @@ class Tests_Post extends WP_UnitTestCase {
'post_status' => 'publish',
)
);
$this->assertEquals( 0, $post_id );
$this->assertSame( 0, $post_id );
$post_id = self::factory()->post->create(
array(
@@ -1581,7 +1581,7 @@ class Tests_Post extends WP_UnitTestCase {
'post_status' => 'publish',
)
);
$this->assertEquals( 0, $post_id );
$this->assertSame( 0, $post_id );
// Valid post_date_gmt
$post_id = self::factory()->post->create(
@@ -1590,7 +1590,7 @@ class Tests_Post extends WP_UnitTestCase {
'post_date_gmt' => $post_date_gmt,
)
);
$this->assertEquals( 0, $post_id );
$this->assertSame( 0, $post_id );
// Invalid post_date_gmt
$post_id = self::factory()->post->create(
@@ -1599,7 +1599,7 @@ class Tests_Post extends WP_UnitTestCase {
'post_date_gmt' => $invalid_date,
)
);
$this->assertEquals( 0, $post_id );
$this->assertSame( 0, $post_id );
}
/**
@@ -1614,19 +1614,19 @@ class Tests_Post extends WP_UnitTestCase {
$this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $resolved_post_date ), 2, 'The dates should be equal' );
$resolved_post_date = wp_resolve_post_date( '', $post_date_gmt );
$this->assertEquals( get_date_from_gmt( $post_date_gmt ), $resolved_post_date );
$this->assertSame( get_date_from_gmt( $post_date_gmt ), $resolved_post_date );
$resolved_post_date = wp_resolve_post_date( '', $invalid_date );
$this->assertEquals( '1970-01-01 00:00:00', $resolved_post_date );
$this->assertSame( '1970-01-01 00:00:00', $resolved_post_date );
$resolved_post_date = wp_resolve_post_date( $post_date );
$this->assertEquals( $post_date, $resolved_post_date );
$this->assertSame( $post_date, $resolved_post_date );
$resolved_post_date = wp_resolve_post_date( $post_date, $post_date_gmt );
$this->assertEquals( $post_date, $resolved_post_date );
$this->assertSame( $post_date, $resolved_post_date );
$resolved_post_date = wp_resolve_post_date( $post_date, $invalid_date );
$this->assertEquals( $post_date, $resolved_post_date );
$this->assertSame( $post_date, $resolved_post_date );
$resolved_post_date = wp_resolve_post_date( $invalid_date );
$this->assertFalse( $resolved_post_date );