Skip to content

Commit 4b96129

Browse files
Tests: Use assertSame() in wp_count_posts() 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 [1323/tests], [25554], [27081], [60788]. Props costdev, SergeyBiryukov. See #64324. git-svn-id: https://develop.svn.wordpress.org/trunk@61417 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b057ff2 commit 4b96129

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tests/phpunit/tests/post.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function test_wp_count_posts() {
183183
);
184184

185185
$count = wp_count_posts( $post_type, 'readable' );
186-
$this->assertEquals( 1, $count->publish );
186+
$this->assertSame( '1', $count->publish );
187187

188188
_unregister_post_type( $post_type );
189189
$count = wp_count_posts( $post_type, 'readable' );
@@ -226,7 +226,7 @@ public function test_wp_count_posts_readable_excludes_unreadable_private_posts()
226226
wp_set_current_user( self::$user_ids['author'] );
227227

228228
$count = wp_count_posts( $post_type, 'readable' );
229-
$this->assertEquals( 5, $count->publish );
229+
$this->assertSame( '5', $count->publish );
230230
_unregister_post_type( $post_type );
231231
}
232232

@@ -245,16 +245,16 @@ public function test_wp_count_posts_filtered() {
245245
);
246246

247247
$count1 = wp_count_posts( $post_type, 'readable' );
248-
$this->assertEquals( 3, $count1->publish );
248+
$this->assertSame( '3', $count1->publish );
249249

250250
add_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
251251
$count2 = wp_count_posts( $post_type, 'readable' );
252252
remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
253-
$this->assertEquals( 2, $count2->publish );
253+
$this->assertSame( '2', $count2->publish );
254254
}
255255

256256
public function filter_wp_count_posts( $counts ) {
257-
$counts->publish = 2;
257+
$counts->publish = '2';
258258
return $counts;
259259
}
260260

@@ -276,8 +276,8 @@ public function test_wp_count_posts_insert_invalidation() {
276276
$this->assertNotEquals( 'publish', $post->post_status );
277277

278278
$after_draft_counts = wp_count_posts();
279-
$this->assertEquals( 1, $after_draft_counts->draft );
280-
$this->assertEquals( 2, $after_draft_counts->publish );
279+
$this->assertSame( '1', $after_draft_counts->draft );
280+
$this->assertSame( '2', $after_draft_counts->publish );
281281
$this->assertNotEquals( $initial_counts->publish, $after_draft_counts->publish );
282282
}
283283

@@ -297,8 +297,8 @@ public function test_wp_count_posts_trash_invalidation() {
297297
$this->assertNotEquals( 'publish', $post->post_status );
298298

299299
$after_trash_counts = wp_count_posts();
300-
$this->assertEquals( 1, $after_trash_counts->trash );
301-
$this->assertEquals( 2, $after_trash_counts->publish );
300+
$this->assertSame( '1', $after_trash_counts->trash );
301+
$this->assertSame( '2', $after_trash_counts->publish );
302302
$this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish );
303303
}
304304

0 commit comments

Comments
 (0)