Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (3 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/getPage.php

    r47122 r48937  
    2626        $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'username', 'password' ) );
    2727        $this->assertIXRError( $result );
    28         $this->assertEquals( 403, $result->code );
     28        $this->assertSame( 403, $result->code );
    2929    }
    3030
     
    3737        $result = $this->myxmlrpcserver->wp_getPage( array( 1, 9999, 'editor', 'editor' ) );
    3838        $this->assertIXRError( $result );
    39         $this->assertEquals( 404, $result->code );
     39        $this->assertSame( 404, $result->code );
    4040    }
    4141
     
    7474        // Check expected values.
    7575        $this->assertStringMatchesFormat( '%d', $result['userid'] );
    76         $this->assertEquals( 'future', $result['page_status'] );
    77         $this->assertEquals( $post_data->post_title, $result['title'] );
    78         $this->assertEquals( url_to_postid( $result['link'] ), self::$post_id );
    79         $this->assertEquals( $post_data->post_excerpt, $result['excerpt'] );
     76        $this->assertSame( 'future', $result['page_status'] );
     77        $this->assertSame( $post_data->post_title, $result['title'] );
     78        $this->assertSame( url_to_postid( $result['link'] ), self::$post_id );
     79        $this->assertSame( $post_data->post_excerpt, $result['excerpt'] );
    8080        $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] );
    8181    }
     
    9494        $date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
    9595
    96         $this->assertEquals( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() );
    97         $this->assertEquals( $date_gmt, $result['date_created_gmt']->getTimestamp() );
     96        $this->assertSame( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() );
     97        $this->assertSame( $date_gmt, $result['date_created_gmt']->getTimestamp() );
    9898    }
    9999}
Note: See TracChangeset for help on using the changeset viewer.