WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months 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/xmlrpc/mw/getPost.php

    r47163 r48937  
    2525        $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'username', 'password' ) );
    2626        $this->assertIXRError( $result );
    27         $this->assertEquals( 403, $result->code );
     27        $this->assertSame( 403, $result->code );
    2828    }
    2929
     
    3333        $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'subscriber', 'subscriber' ) );
    3434        $this->assertIXRError( $result );
    35         $this->assertEquals( 401, $result->code );
     35        $this->assertSame( 401, $result->code );
    3636    }
    3737
     
    4242        $result = $this->myxmlrpcserver->mw_getPost( array( 9999, 'author', 'author' ) );
    4343        $this->assertIXRError( $result );
    44         $this->assertEquals( 404, $result->code );
     44        $this->assertSame( 404, $result->code );
    4545    }
    4646
     
    7979        // Check expected values.
    8080        $this->assertStringMatchesFormat( '%d', $result['userid'] );
    81         $this->assertEquals( $post_data->post_title, $result['title'] );
    82         $this->assertEquals( 'publish', $result['post_status'] );
     81        $this->assertSame( $post_data->post_title, $result['title'] );
     82        $this->assertSame( 'publish', $result['post_status'] );
    8383        $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] );
    84         $this->assertEquals( $post_data->post_excerpt, $result['mt_excerpt'] );
    85         $this->assertEquals( url_to_postid( $result['link'] ), self::$post_id );
     84        $this->assertSame( $post_data->post_excerpt, $result['mt_excerpt'] );
     85        $this->assertSame( url_to_postid( $result['link'] ), self::$post_id );
    8686
    87         $this->assertEquals( 0, $result['wp_post_thumbnail'] );
     87        $this->assertSame( 0, $result['wp_post_thumbnail'] );
    8888
    8989        remove_theme_support( 'post-thumbnails' );
     
    104104
    105105        $this->assertInternalType( 'int', $result['wp_post_thumbnail'] );
    106         $this->assertEquals( $attachment_id, $result['wp_post_thumbnail'] );
     106        $this->assertSame( $attachment_id, $result['wp_post_thumbnail'] );
    107107
    108108        remove_theme_support( 'post-thumbnails' );
     
    121121        $post_data = get_post( self::$post_id );
    122122
    123         $this->assertEquals( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() );
    124         $this->assertEquals( strtotime( $post_data->post_date ), $result['date_modified']->getTimestamp() );
     123        $this->assertSame( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() );
     124        $this->assertSame( strtotime( $post_data->post_date ), $result['date_modified']->getTimestamp() );
    125125
    126126        $post_date_gmt     = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
    127127        $post_modified_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
    128128
    129         $this->assertEquals( $post_date_gmt, $result['date_created_gmt']->getTimestamp() );
    130         $this->assertEquals( $post_modified_gmt, $result['date_modified_gmt']->getTimestamp() );
     129        $this->assertSame( $post_date_gmt, $result['date_created_gmt']->getTimestamp() );
     130        $this->assertSame( $post_modified_gmt, $result['date_modified_gmt']->getTimestamp() );
    131131    }
    132132}
Note: See TracChangeset for help on using the changeset viewer.