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/atom.php

    r48435 r48937  
    9898
    9999        // Verify attributes.
    100         $this->assertEquals( 'http://www.w3.org/2005/Atom', $atom[0]['attributes']['xmlns'] );
    101         $this->assertEquals( 'http://purl.org/syndication/thread/1.0', $atom[0]['attributes']['xmlns:thr'] );
    102         $this->assertEquals( site_url( '/wp-atom.php' ), $atom[0]['attributes']['xml:base'] );
     100        $this->assertSame( 'http://www.w3.org/2005/Atom', $atom[0]['attributes']['xmlns'] );
     101        $this->assertSame( 'http://purl.org/syndication/thread/1.0', $atom[0]['attributes']['xmlns:thr'] );
     102        $this->assertSame( site_url( '/wp-atom.php' ), $atom[0]['attributes']['xml:base'] );
    103103
    104104        // Verify the <feed> element is present and contains a <title> child element.
    105105        $title = xml_find( $xml, 'feed', 'title' );
    106         $this->assertEquals( get_option( 'blogname' ), $title[0]['content'] );
     106        $this->assertSame( get_option( 'blogname' ), $title[0]['content'] );
    107107
    108108        // Verify the <feed> element is present and contains a <updated> child element.
    109109        $updated = xml_find( $xml, 'feed', 'updated' );
    110         $this->assertEquals( strtotime( get_lastpostmodified() ), strtotime( $updated[0]['content'] ) );
     110        $this->assertSame( strtotime( get_lastpostmodified() ), strtotime( $updated[0]['content'] ) );
    111111
    112112        // Verify the <feed> element is present and contains a <subtitle> child element.
    113113        $subtitle = xml_find( $xml, 'feed', 'subtitle' );
    114         $this->assertEquals( get_option( 'blogdescription' ), $subtitle[0]['content'] );
     114        $this->assertSame( get_option( 'blogdescription' ), $subtitle[0]['content'] );
    115115
    116116        // Verify the <feed> element is present and contains two <link> child elements.
     
    119119
    120120        // Verify the <feed> element is present and contains a <link rel="alternate"> child element.
    121         $this->assertEquals( 'alternate', $link[0]['attributes']['rel'] );
    122         $this->assertEquals( home_url(), $link[0]['attributes']['href'] );
     121        $this->assertSame( 'alternate', $link[0]['attributes']['rel'] );
     122        $this->assertSame( home_url(), $link[0]['attributes']['href'] );
    123123
    124124        // Verify the <feed> element is present and contains a <link rel="href"> child element.
    125         $this->assertEquals( 'self', $link[1]['attributes']['rel'] );
    126         $this->assertEquals( home_url( '/?feed=atom' ), $link[1]['attributes']['href'] );
     125        $this->assertSame( 'self', $link[1]['attributes']['rel'] );
     126        $this->assertSame( home_url( '/?feed=atom' ), $link[1]['attributes']['href'] );
    127127    }
    128128
     
    155155            $author = xml_find( $entries[ $key ]['child'], 'author', 'name' );
    156156            $user   = new WP_User( $post->post_author );
    157             $this->assertEquals( $user->display_name, $author[0]['content'] );
     157            $this->assertSame( $user->display_name, $author[0]['content'] );
    158158
    159159            // Title.
    160160            $title = xml_find( $entries[ $key ]['child'], 'title' );
    161             $this->assertEquals( $post->post_title, $title[0]['content'] );
     161            $this->assertSame( $post->post_title, $title[0]['content'] );
    162162
    163163            // Link rel="alternate".
     
    165165            foreach ( $link_alts as $link_alt ) {
    166166                if ( 'alternate' === $link_alt['attributes']['rel'] ) {
    167                     $this->assertEquals( get_permalink( $post ), $link_alt['attributes']['href'] );
     167                    $this->assertSame( get_permalink( $post ), $link_alt['attributes']['href'] );
    168168                }
    169169            }
     
    171171            // ID.
    172172            $guid = xml_find( $entries[ $key ]['child'], 'id' );
    173             $this->assertEquals( $post->guid, $id[0]['content'] );
     173            $this->assertSame( $post->guid, $id[0]['content'] );
    174174
    175175            // Updated.
    176176            $updated = xml_find( $entries[ $key ]['child'], 'updated' );
    177             $this->assertEquals( strtotime( $post->post_modified_gmt ), strtotime( $updated[0]['content'] ) );
     177            $this->assertSame( strtotime( $post->post_modified_gmt ), strtotime( $updated[0]['content'] ) );
    178178
    179179            // Published.
    180180            $published = xml_find( $entries[ $key ]['child'], 'published' );
    181             $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $published[0]['content'] ) );
     181            $this->assertSame( strtotime( $post->post_date_gmt ), strtotime( $published[0]['content'] ) );
    182182
    183183            // Category.
     
    194194            if ( ! $this->excerpt_only ) {
    195195                $content = xml_find( $entries[ $key ]['child'], 'content' );
    196                 $this->assertEquals( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) );
     196                $this->assertSame( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) );
    197197            }
    198198
     
    201201            foreach ( $link_replies as $link_reply ) {
    202202                if ( 'replies' === $link_reply['attributes']['rel'] && 'application/atom+xml' === $link_reply['attributes']['type'] ) {
    203                     $this->assertEquals( get_post_comments_feed_link( $post->ID, 'atom' ), $link_reply['attributes']['href'] );
     203                    $this->assertSame( get_post_comments_feed_link( $post->ID, 'atom' ), $link_reply['attributes']['href'] );
    204204                }
    205205            }
     
    274274            foreach ( (array) $links as $link ) {
    275275                if ( 'enclosure' === $link['attributes']['rel'] ) {
    276                     $this->assertEquals( $enclosures[ $i ]['expected']['href'], $link['attributes']['href'] );
     276                    $this->assertSame( $enclosures[ $i ]['expected']['href'], $link['attributes']['href'] );
    277277                    $this->assertEquals( $enclosures[ $i ]['expected']['length'], $link['attributes']['length'] );
    278                     $this->assertEquals( $enclosures[ $i ]['expected']['type'], $link['attributes']['type'] );
     278                    $this->assertSame( $enclosures[ $i ]['expected']['type'], $link['attributes']['type'] );
    279279                    $i++;
    280280                }
Note: See TracChangeset for help on using the changeset viewer.