Make WordPress Core


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

    r47122 r48937  
    3232        $result = $this->myxmlrpcserver->wp_getPost( array( 1, 'username', 'password', 1 ) );
    3333        $this->assertIXRError( $result );
    34         $this->assertEquals( 403, $result->code );
     34        $this->assertSame( 403, $result->code );
    3535    }
    3636
     
    6666        // Check expected values.
    6767        $this->assertStringMatchesFormat( '%d', $result['post_id'] );
    68         $this->assertEquals( $this->post_data['post_title'], $result['post_title'] );
    69         $this->assertEquals( 'draft', $result['post_status'] );
    70         $this->assertEquals( 'post', $result['post_type'] );
     68        $this->assertSame( $this->post_data['post_title'], $result['post_title'] );
     69        $this->assertSame( 'draft', $result['post_status'] );
     70        $this->assertSame( 'post', $result['post_type'] );
    7171        $this->assertStringMatchesFormat( '%d', $result['post_author'] );
    72         $this->assertEquals( $this->post_data['post_excerpt'], $result['post_excerpt'] );
    73         $this->assertEquals( $this->post_data['post_content'], $result['post_content'] );
    74         $this->assertEquals( url_to_postid( $result['link'] ), $this->post_id );
     72        $this->assertSame( $this->post_data['post_excerpt'], $result['post_excerpt'] );
     73        $this->assertSame( $this->post_data['post_content'], $result['post_content'] );
     74        $this->assertSame( url_to_postid( $result['link'] ), $this->post_id );
    7575        $this->assertEquals( $this->post_custom_field['id'], $result['custom_fields'][0]['id'] );
    76         $this->assertEquals( $this->post_custom_field['key'], $result['custom_fields'][0]['key'] );
     76        $this->assertSame( $this->post_custom_field['key'], $result['custom_fields'][0]['key'] );
    7777        $this->assertEquals( $this->post_custom_field['value'], $result['custom_fields'][0]['value'] );
    7878
     
    8686
    8787        // When no fields are requested, only the IDs should be returned.
    88         $this->assertEquals( 1, count( $result ) );
    89         $this->assertEquals( array( 'post_id' ), array_keys( $result ) );
     88        $this->assertSame( 1, count( $result ) );
     89        $this->assertSame( array( 'post_id' ), array_keys( $result ) );
    9090    }
    9191
     
    110110        $this->assertInstanceOf( 'IXR_Date', $result['post_modified_gmt'] );
    111111
    112         $this->assertEquals( $this->post_date_ts, $result['post_date']->getTimestamp() );
    113         $this->assertEquals( $this->post_date_ts, $result['post_modified']->getTimestamp() );
     112        $this->assertSame( $this->post_date_ts, $result['post_date']->getTimestamp() );
     113        $this->assertSame( $this->post_date_ts, $result['post_modified']->getTimestamp() );
    114114
    115115        $post_date_gmt     = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ) );
    116116        $post_modified_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ) );
    117117
    118         $this->assertEquals( $post_date_gmt, $result['post_date_gmt']->getTimestamp() );
    119         $this->assertEquals( $post_modified_gmt, $result['post_modified_gmt']->getTimestamp() );
     118        $this->assertSame( $post_date_gmt, $result['post_date_gmt']->getTimestamp() );
     119        $this->assertSame( $post_modified_gmt, $result['post_modified_gmt']->getTimestamp() );
    120120    }
    121121
     
    144144        $this->assertInternalType( 'string', $result['post_mime_type'] );
    145145
    146         $this->assertEquals( 'page', $result['post_type'] );
     146        $this->assertSame( 'page', $result['post_type'] );
    147147        $this->assertEquals( $parent_page_id, $result['post_parent'] );
    148         $this->assertEquals( 2, $result['menu_order'] );
     148        $this->assertSame( 2, $result['menu_order'] );
    149149    }
    150150}
Note: See TracChangeset for help on using the changeset viewer.