Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/formats.php

    r47122 r48937  
    1818        $this->assertNotWPError( $result );
    1919        $this->assertInternalType( 'array', $result );
    20         $this->assertEquals( 1, count( $result ) );
     20        $this->assertSame( 1, count( $result ) );
    2121
    2222        $format = get_post_format( $post_id );
    23         $this->assertEquals( 'aside', $format );
     23        $this->assertSame( 'aside', $format );
    2424
    2525        $result = set_post_format( $post_id, 'standard' );
    2626        $this->assertNotWPError( $result );
    2727        $this->assertInternalType( 'array', $result );
    28         $this->assertEquals( 0, count( $result ) );
     28        $this->assertSame( 0, count( $result ) );
    2929
    3030        $result = set_post_format( $post_id, '' );
    3131        $this->assertNotWPError( $result );
    3232        $this->assertInternalType( 'array', $result );
    33         $this->assertEquals( 0, count( $result ) );
     33        $this->assertSame( 0, count( $result ) );
    3434    }
    3535
     
    4646        $this->assertNotWPError( $result );
    4747        $this->assertInternalType( 'array', $result );
    48         $this->assertEquals( 1, count( $result ) );
     48        $this->assertSame( 1, count( $result ) );
    4949        // The format can be set but not retrieved until it is registered.
    5050        $format = get_post_format( $post_id );
     
    5454        // The previous set can now be retrieved.
    5555        $format = get_post_format( $post_id );
    56         $this->assertEquals( 'aside', $format );
     56        $this->assertSame( 'aside', $format );
    5757
    5858        $result = set_post_format( $post_id, 'standard' );
    5959        $this->assertNotWPError( $result );
    6060        $this->assertInternalType( 'array', $result );
    61         $this->assertEquals( 0, count( $result ) );
     61        $this->assertSame( 0, count( $result ) );
    6262
    6363        $result = set_post_format( $post_id, '' );
    6464        $this->assertNotWPError( $result );
    6565        $this->assertInternalType( 'array', $result );
    66         $this->assertEquals( 0, count( $result ) );
     66        $this->assertSame( 0, count( $result ) );
    6767
    6868        remove_post_type_support( 'page', 'post-formats' );
     
    7878        $this->assertNotWPError( $result );
    7979        $this->assertInternalType( 'array', $result );
    80         $this->assertEquals( 1, count( $result ) );
     80        $this->assertSame( 1, count( $result ) );
    8181        $this->assertTrue( has_post_format( 'aside', $post_id ) );
    8282
     
    8484        $this->assertNotWPError( $result );
    8585        $this->assertInternalType( 'array', $result );
    86         $this->assertEquals( 0, count( $result ) );
     86        $this->assertSame( 0, count( $result ) );
    8787        // Standard is a special case. It shows as false when set.
    8888        $this->assertFalse( has_post_format( 'standard', $post_id ) );
     
    114114        $link_post_id         = self::factory()->post->create( array( 'post_content' => $link ) );
    115115        $content_link         = get_url_in_content( get_post_field( 'post_content', $link_post_id ) );
    116         $this->assertEquals( false, $content_link );
     116        $this->assertFalse( $content_link );
    117117
    118118        $link_with_post_id = self::factory()->post->create( array( 'post_content' => $link_with_commentary ) );
    119119        $content_link      = get_url_in_content( get_post_field( 'post_content', $link_with_post_id ) );
    120         $this->assertEquals( false, $content_link );
     120        $this->assertFalse( $content_link );
    121121
    122122        $content_link = get_url_in_content( get_post_field( 'post_content', $link_post_id ) );
    123         $this->assertEquals( false, $content_link );
     123        $this->assertFalse( $content_link );
    124124
    125125        $content_link = get_url_in_content( get_post_field( 'post_content', $link_with_post_id ) );
    126         $this->assertEquals( false, $content_link );
     126        $this->assertFalse( $content_link );
    127127
    128128        $empty_post_id = self::factory()->post->create( array( 'post_content' => '' ) );
    129129        $content_link  = get_url_in_content( get_post_field( 'post_content', $empty_post_id ) );
    130         $this->assertEquals( false, $content_link );
     130        $this->assertFalse( $content_link );
    131131
    132132        $comm_post_id = self::factory()->post->create( array( 'post_content' => $commentary ) );
    133133        $content_link = get_url_in_content( get_post_field( 'post_content', $comm_post_id ) );
    134         $this->assertEquals( false, $content_link );
     134        $this->assertFalse( $content_link );
    135135
    136136        // Now with an href.
    137137        $href_post_id = self::factory()->post->create( array( 'post_content' => $href ) );
    138138        $content_link = get_url_in_content( get_post_field( 'post_content', $href_post_id ) );
    139         $this->assertEquals( $link, $content_link );
     139        $this->assertSame( $link, $content_link );
    140140
    141141        $href_with_post_id = self::factory()->post->create( array( 'post_content' => $href_with_commentary ) );
    142142        $content_link      = get_url_in_content( get_post_field( 'post_content', $href_with_post_id ) );
    143         $this->assertEquals( $link, $content_link );
     143        $this->assertSame( $link, $content_link );
    144144
    145145        $content_link = get_url_in_content( get_post_field( 'post_content', $href_post_id ) );
    146         $this->assertEquals( $link, $content_link );
     146        $this->assertSame( $link, $content_link );
    147147
    148148        $content_link = get_url_in_content( get_post_field( 'post_content', $href_with_post_id ) );
    149         $this->assertEquals( $link, $content_link );
     149        $this->assertSame( $link, $content_link );
    150150
    151151        $empty_post_id = self::factory()->post->create( array( 'post_content' => '' ) );
    152152        $content_link  = get_url_in_content( get_post_field( 'post_content', $empty_post_id ) );
    153         $this->assertEquals( false, $content_link );
     153        $this->assertFalse( $content_link );
    154154
    155155        $comm_post_id = self::factory()->post->create( array( 'post_content' => $commentary ) );
    156156        $content_link = get_url_in_content( get_post_field( 'post_content', $comm_post_id ) );
    157         $this->assertEquals( false, $content_link );
     157        $this->assertFalse( $content_link );
    158158    }
    159159}
Note: See TracChangeset for help on using the changeset viewer.