Make WordPress Core

Changeset 62247


Ignore:
Timestamp:
04/20/2026 11:11:32 PM (3 weeks ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/link/getAdjacentPost.php

    r61424 r62247  
    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.
     
    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
     
    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
     
    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.
     
    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.
     
    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
     
    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
     
    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}
Note: See TracChangeset for help on using the changeset viewer.