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/feed/rss2.php

    r47198 r48937  
    107107
    108108        // There should only be one <rss> child element.
    109         $this->assertEquals( 1, count( $rss ) );
    110 
    111         $this->assertEquals( '2.0', $rss[0]['attributes']['version'] );
    112         $this->assertEquals( 'http://purl.org/rss/1.0/modules/content/', $rss[0]['attributes']['xmlns:content'] );
    113         $this->assertEquals( 'http://wellformedweb.org/CommentAPI/', $rss[0]['attributes']['xmlns:wfw'] );
    114         $this->assertEquals( 'http://purl.org/dc/elements/1.1/', $rss[0]['attributes']['xmlns:dc'] );
     109        $this->assertSame( 1, count( $rss ) );
     110
     111        $this->assertSame( '2.0', $rss[0]['attributes']['version'] );
     112        $this->assertSame( 'http://purl.org/rss/1.0/modules/content/', $rss[0]['attributes']['xmlns:content'] );
     113        $this->assertSame( 'http://wellformedweb.org/CommentAPI/', $rss[0]['attributes']['xmlns:wfw'] );
     114        $this->assertSame( 'http://purl.org/dc/elements/1.1/', $rss[0]['attributes']['xmlns:dc'] );
    115115
    116116        // RSS should have exactly one child element (channel).
    117         $this->assertEquals( 1, count( $rss[0]['child'] ) );
     117        $this->assertSame( 1, count( $rss[0]['child'] ) );
    118118    }
    119119
     
    136136        // Verify the channel is present and contains a title child element.
    137137        $title = xml_find( $xml, 'rss', 'channel', 'title' );
    138         $this->assertEquals( get_option( 'blogname' ), $title[0]['content'] );
     138        $this->assertSame( get_option( 'blogname' ), $title[0]['content'] );
    139139
    140140        $desc = xml_find( $xml, 'rss', 'channel', 'description' );
    141         $this->assertEquals( get_option( 'blogdescription' ), $desc[0]['content'] );
     141        $this->assertSame( get_option( 'blogdescription' ), $desc[0]['content'] );
    142142
    143143        $link = xml_find( $xml, 'rss', 'channel', 'link' );
    144         $this->assertEquals( get_option( 'siteurl' ), $link[0]['content'] );
     144        $this->assertSame( get_option( 'siteurl' ), $link[0]['content'] );
    145145
    146146        $pubdate = xml_find( $xml, 'rss', 'channel', 'lastBuildDate' );
    147         $this->assertEquals( strtotime( get_lastpostmodified() ), strtotime( $pubdate[0]['content'] ) );
     147        $this->assertSame( strtotime( get_lastpostmodified() ), strtotime( $pubdate[0]['content'] ) );
    148148    }
    149149
     
    200200            // Title.
    201201            $title = xml_find( $items[ $key ]['child'], 'title' );
    202             $this->assertEquals( $post->post_title, $title[0]['content'] );
     202            $this->assertSame( $post->post_title, $title[0]['content'] );
    203203
    204204            // Link.
    205205            $link = xml_find( $items[ $key ]['child'], 'link' );
    206             $this->assertEquals( get_permalink( $post ), $link[0]['content'] );
     206            $this->assertSame( get_permalink( $post ), $link[0]['content'] );
    207207
    208208            // Comment link.
    209209            $comments_link = xml_find( $items[ $key ]['child'], 'comments' );
    210             $this->assertEquals( get_permalink( $post ) . '#respond', $comments_link[0]['content'] );
     210            $this->assertSame( get_permalink( $post ) . '#respond', $comments_link[0]['content'] );
    211211
    212212            // Pub date.
    213213            $pubdate = xml_find( $items[ $key ]['child'], 'pubDate' );
    214             $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) );
     214            $this->assertSame( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) );
    215215
    216216            // Author.
    217217            $creator = xml_find( $items[ $key ]['child'], 'dc:creator' );
    218218            $user    = new WP_User( $post->post_author );
    219             $this->assertEquals( $user->display_name, $creator[0]['content'] );
     219            $this->assertSame( $user->display_name, $creator[0]['content'] );
    220220
    221221            // Categories (perhaps multiple).
     
    234234            $cats = array_filter( $cats );
    235235            // Should be the same number of categories.
    236             $this->assertEquals( count( $cats ), count( $categories ) );
     236            $this->assertSame( count( $cats ), count( $categories ) );
    237237
    238238            // ..with the same names.
    239239            foreach ( $cats as $id => $cat ) {
    240                 $this->assertEquals( $cat, $categories[ $id ]['content'] );
     240                $this->assertSame( $cat, $categories[ $id ]['content'] );
    241241            }
    242242
    243243            // GUID.
    244244            $guid = xml_find( $items[ $key ]['child'], 'guid' );
    245             $this->assertEquals( 'false', $guid[0]['attributes']['isPermaLink'] );
    246             $this->assertEquals( $post->guid, $guid[0]['content'] );
     245            $this->assertSame( 'false', $guid[0]['attributes']['isPermaLink'] );
     246            $this->assertSame( $post->guid, $guid[0]['content'] );
    247247
    248248            // Description / Excerpt.
    249249            if ( ! empty( $post->post_excerpt ) ) {
    250250                $description = xml_find( $items[ $key ]['child'], 'description' );
    251                 $this->assertEquals( trim( $post->post_excerpt ), trim( $description[0]['content'] ) );
     251                $this->assertSame( trim( $post->post_excerpt ), trim( $description[0]['content'] ) );
    252252            }
    253253
     
    255255            if ( ! $this->excerpt_only ) {
    256256                $content = xml_find( $items[ $key ]['child'], 'content:encoded' );
    257                 $this->assertEquals( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) );
     257                $this->assertSame( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) );
    258258            }
    259259
    260260            // Comment RSS.
    261261            $comment_rss = xml_find( $items[ $key ]['child'], 'wfw:commentRss' );
    262             $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID ) ), $comment_rss[0]['content'] );
     262            $this->assertSame( html_entity_decode( get_post_comments_feed_link( $post->ID ) ), $comment_rss[0]['content'] );
    263263        }
    264264    }
     
    321321
    322322        // There should only be one <rss> child element.
    323         $this->assertEquals( 1, count( $rss ) );
     323        $this->assertSame( 1, count( $rss ) );
    324324    }
    325325
     
    349349
    350350        // There should only be one <rss> child element.
    351         $this->assertEquals( 1, count( $rss ) );
     351        $this->assertSame( 1, count( $rss ) );
    352352    }
    353353
     
    382382
    383383        // There should only be one <rss> child element.
    384         $this->assertEquals( 1, count( $rss ) );
     384        $this->assertSame( 1, count( $rss ) );
    385385    }
    386386
     
    410410
    411411        // There should only be one <rss> child element.
    412         $this->assertEquals( 1, count( $rss ) );
     412        $this->assertSame( 1, count( $rss ) );
    413413    }
    414414
     
    438438
    439439        // There should only be one <rss> child element.
    440         $this->assertEquals( 1, count( $rss ) );
     440        $this->assertSame( 1, count( $rss ) );
    441441    }
    442442
     
    466466
    467467        // There should only be one <rss> child element.
    468         $this->assertEquals( 1, count( $rss ) );
     468        $this->assertSame( 1, count( $rss ) );
    469469    }
    470470
     
    484484        $rss             = xml_find( $xml, $element );
    485485        $last_build_date = $rss[0]['child'][0]['child'][4]['content'];
    486         $this->assertEquals( strtotime( get_feed_build_date( 'r' ) ), strtotime( $last_build_date ) );
     486        $this->assertSame( strtotime( get_feed_build_date( 'r' ) ), strtotime( $last_build_date ) );
    487487    }
    488488
Note: See TracChangeset for help on using the changeset viewer.