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/mw/editPost.php

    r47122 r48937  
    1010        $result = $this->myxmlrpcserver->mw_editPost( array( 1, 'username', 'password', $post ) );
    1111        $this->assertIXRError( $result );
    12         $this->assertEquals( 403, $result->code );
     12        $this->assertSame( 403, $result->code );
    1313    }
    1414
     
    2828
    2929        $out = get_post( $post_id );
    30         $this->assertEquals( $new_title, $out->post_title );
     30        $this->assertSame( $new_title, $out->post_title );
    3131    }
    3232
     
    4848
    4949        $out = get_post( $post_id );
    50         $this->assertEquals( $new_title, $out->post_title );
     50        $this->assertSame( $new_title, $out->post_title );
    5151    }
    5252
     
    6666        $result    = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
    6767        $this->assertIXRError( $result );
    68         $this->assertEquals( 401, $result->code );
    69 
    70         $out = get_post( $post_id );
    71         $this->assertEquals( $original_title, $out->post_title );
     68        $this->assertSame( 401, $result->code );
     69
     70        $out = get_post( $post_id );
     71        $this->assertSame( $original_title, $out->post_title );
    7272    }
    7373
     
    105105        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
    106106        $this->assertIXRError( $result );
    107         $this->assertEquals( 401, $result->code );
     107        $this->assertSame( 401, $result->code );
    108108
    109109        $out = get_post( $post_id );
     
    144144        $post_id = wp_insert_post( $post );
    145145
    146         $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
     146        $this->assertSame( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
    147147
    148148        // Create attachment.
     
    175175        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post5 ) );
    176176        $this->assertNotIXRError( $result );
    177         $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
     177        $this->assertSame( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
    178178
    179179        remove_theme_support( 'post-thumbnails' );
     
    200200
    201201        $out = get_post( $post_id );
    202         $this->assertEquals( $post2['title'], $out->post_title );
     202        $this->assertSame( $post2['title'], $out->post_title );
    203203
    204204        $post3  = array(
     
    211211
    212212        $out = get_post( $post_id );
    213         $this->assertEquals( $post2['title'], $out->post_title );
    214         $this->assertEquals( $post3['description'], $out->post_content );
     213        $this->assertSame( $post2['title'], $out->post_title );
     214        $this->assertSame( $post3['description'], $out->post_content );
    215215
    216216        $post4  = array(
     
    223223
    224224        $out = get_post( $post_id );
    225         $this->assertEquals( $post2['title'], $out->post_title );
    226         $this->assertEquals( $post3['description'], $out->post_content );
    227         $this->assertEquals( $post4['mt_excerpt'], $out->post_excerpt );
     225        $this->assertSame( $post2['title'], $out->post_title );
     226        $this->assertSame( $post3['description'], $out->post_content );
     227        $this->assertSame( $post4['mt_excerpt'], $out->post_excerpt );
    228228    }
    229229
     
    260260        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
    261261        $this->assertIXRError( $result );
    262         $this->assertEquals( $result->code, 401 );
     262        $this->assertSame( $result->code, 401 );
    263263    }
    264264
     
    328328
    329329        $after = get_post( $post_id );
    330         $this->assertEquals( 'future', $after->post_status );
     330        $this->assertSame( 'future', $after->post_status );
    331331
    332332        $future_date_string = strftime( '%Y-%m-%d %H:%M:%S', $future_time );
    333         $this->assertEquals( $future_date_string, $after->post_date );
     333        $this->assertSame( $future_date_string, $after->post_date );
    334334    }
    335335}
Note: See TracChangeset for help on using the changeset viewer.