Skip to content

Commit 67094ee

Browse files
Tests: Use assertSame() in get_adjacent_post() 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 [60733], [61066]. Props sagardeshmukh. See #64324. git-svn-id: https://develop.svn.wordpress.org/trunk@62247 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 047ef80 commit 67094ee

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tests/phpunit/tests/link/getAdjacentPost.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,14 @@ public function test_get_adjacent_post_term_array_processing_order() {
477477

478478
// Should find post_one (previous post that shares term1).
479479
$this->assertInstanceOf( WP_Post::class, $result );
480-
$this->assertEquals( $post1_id, $result->ID );
480+
$this->assertSame( $post1_id, $result->ID );
481481

482482
// Test next post.
483483
$result = get_adjacent_post( true, array( $term2_id ), false, 'wptests_tax' );
484484

485485
// Should find post_three (next post that shares term1).
486486
$this->assertInstanceOf( WP_Post::class, $result );
487-
$this->assertEquals( $post3_id, $result->ID );
487+
$this->assertSame( $post3_id, $result->ID );
488488
}
489489

490490
/**
@@ -614,12 +614,12 @@ public function test_get_adjacent_post_with_identical_dates() {
614614
// Previous post should be the 2nd post (lower ID, same date).
615615
$previous = get_adjacent_post( false, '', true );
616616
$this->assertInstanceOf( 'WP_Post', $previous );
617-
$this->assertEquals( $post_ids[1], $previous->ID );
617+
$this->assertSame( $post_ids[1], $previous->ID );
618618

619619
// Next post should be the 4th post (higher ID, same date).
620620
$next = get_adjacent_post( false, '', false );
621621
$this->assertInstanceOf( 'WP_Post', $next );
622-
$this->assertEquals( $post_ids[3], $next->ID );
622+
$this->assertSame( $post_ids[3], $next->ID );
623623
}
624624

625625
/**
@@ -661,38 +661,38 @@ public function test_get_adjacent_post_mixed_dates_with_identical_groups() {
661661
// Previous should be the early post (different date).
662662
$previous = get_adjacent_post( false, '', true );
663663
$this->assertInstanceOf( 'WP_Post', $previous );
664-
$this->assertEquals( $post_early, $previous->ID );
664+
$this->assertSame( $post_early, $previous->ID );
665665

666666
// Next should be the second identical post (same date, higher ID).
667667
$next = get_adjacent_post( false, '', false );
668668
$this->assertInstanceOf( 'WP_Post', $next );
669-
$this->assertEquals( $post_ids[1], $next->ID );
669+
$this->assertSame( $post_ids[1], $next->ID );
670670

671671
// Test from middle identical post.
672672
$this->go_to( get_permalink( $post_ids[1] ) );
673673

674674
// Previous should be the first identical post (same date, lower ID).
675675
$previous = get_adjacent_post( false, '', true );
676676
$this->assertInstanceOf( 'WP_Post', $previous );
677-
$this->assertEquals( $post_ids[0], $previous->ID );
677+
$this->assertSame( $post_ids[0], $previous->ID );
678678

679679
// Next should be the third identical post (same date, higher ID).
680680
$next = get_adjacent_post( false, '', false );
681681
$this->assertInstanceOf( 'WP_Post', $next );
682-
$this->assertEquals( $post_ids[2], $next->ID );
682+
$this->assertSame( $post_ids[2], $next->ID );
683683

684684
// Test from last identical post.
685685
$this->go_to( get_permalink( $post_ids[2] ) );
686686

687687
// Previous should be the second identical post (same date, lower ID).
688688
$previous = get_adjacent_post( false, '', true );
689689
$this->assertInstanceOf( 'WP_Post', $previous );
690-
$this->assertEquals( $post_ids[1], $previous->ID );
690+
$this->assertSame( $post_ids[1], $previous->ID );
691691

692692
// Next should be the late post (different date).
693693
$next = get_adjacent_post( false, '', false );
694694
$this->assertInstanceOf( 'WP_Post', $next );
695-
$this->assertEquals( $post_late, $next->ID );
695+
$this->assertSame( $post_late, $next->ID );
696696
}
697697

698698
/**
@@ -719,26 +719,26 @@ public function test_get_adjacent_post_navigation_through_identical_dates() {
719719

720720
// From post 1, next should be post 2.
721721
$next = get_adjacent_post( false, '', false );
722-
$this->assertEquals( $post_ids[1], $next->ID );
722+
$this->assertSame( $post_ids[1], $next->ID );
723723

724724
// From post 2, previous should be post 1, next should be post 3.
725725
$this->go_to( get_permalink( $post_ids[1] ) );
726726
$previous = get_adjacent_post( false, '', true );
727-
$this->assertEquals( $post_ids[0], $previous->ID );
727+
$this->assertSame( $post_ids[0], $previous->ID );
728728
$next = get_adjacent_post( false, '', false );
729-
$this->assertEquals( $post_ids[2], $next->ID );
729+
$this->assertSame( $post_ids[2], $next->ID );
730730

731731
// From post 3, previous should be post 2, next should be post 4.
732732
$this->go_to( get_permalink( $post_ids[2] ) );
733733
$previous = get_adjacent_post( false, '', true );
734-
$this->assertEquals( $post_ids[1], $previous->ID );
734+
$this->assertSame( $post_ids[1], $previous->ID );
735735
$next = get_adjacent_post( false, '', false );
736-
$this->assertEquals( $post_ids[3], $next->ID );
736+
$this->assertSame( $post_ids[3], $next->ID );
737737

738738
// From post 4, previous should be post 3.
739739
$this->go_to( get_permalink( $post_ids[3] ) );
740740
$previous = get_adjacent_post( false, '', true );
741-
$this->assertEquals( $post_ids[2], $previous->ID );
741+
$this->assertSame( $post_ids[2], $previous->ID );
742742
}
743743

744744
/**
@@ -777,6 +777,6 @@ public function test_get_adjacent_post_identical_dates_with_category() {
777777

778778
$next = get_adjacent_post( true, '', false, 'category' );
779779
$this->assertInstanceOf( 'WP_Post', $next );
780-
$this->assertEquals( $post_ids[3], $next->ID ); // Post 4 (in category)
780+
$this->assertSame( $post_ids[3], $next->ID ); // Post 4 (in category)
781781
}
782782
}

0 commit comments

Comments
 (0)