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/xmlrpc/wp/newPost.php

    r47122 r48937  
    99        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'username', 'password', array() ) );
    1010        $this->assertIXRError( $result );
    11         $this->assertEquals( 403, $result->code );
     11        $this->assertSame( 403, $result->code );
    1212    }
    1313
     
    1717        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'subscriber', 'subscriber', array() ) );
    1818        $this->assertIXRError( $result );
    19         $this->assertEquals( 401, $result->code );
     19        $this->assertSame( 401, $result->code );
    2020    }
    2121
     
    2525        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', array() ) );
    2626        $this->assertIXRError( $result );
    27         $this->assertEquals( 500, $result->code );
    28         $this->assertEquals( 'Content, title, and excerpt are empty.', $result->message );
     27        $this->assertSame( 500, $result->code );
     28        $this->assertSame( 'Content, title, and excerpt are empty.', $result->message );
    2929    }
    3030
     
    7070        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    7171        $this->assertIXRError( $result );
    72         $this->assertEquals( 401, $result->code );
     72        $this->assertSame( 401, $result->code );
    7373    }
    7474
     
    9393        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    9494        $this->assertIXRError( $result );
    95         $this->assertEquals( 401, $result->code );
     95        $this->assertSame( 401, $result->code );
    9696    }
    9797
     
    118118        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    119119        $this->assertIXRError( $result );
    120         $this->assertEquals( 401, $result->code );
     120        $this->assertSame( 401, $result->code );
    121121    }
    122122
     
    130130        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    131131        $this->assertIXRError( $result );
    132         $this->assertEquals( 404, $result->code );
     132        $this->assertSame( 404, $result->code );
    133133    }
    134134
     
    143143        $out = get_post( $result );
    144144        $this->assertEquals( $my_author_id, $out->post_author );
    145         $this->assertEquals( 'Test', $out->post_title );
     145        $this->assertSame( 'Test', $out->post_title );
    146146    }
    147147
     
    175175        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    176176        $this->assertNotIXRError( $result );
    177         $this->assertEquals( 'draft', get_post_status( $result ) );
     177        $this->assertSame( 'draft', get_post_status( $result ) );
    178178    }
    179179
     
    187187        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    188188        $this->assertIXRError( $result );
    189         $this->assertEquals( 401, $result->code );
     189        $this->assertSame( 401, $result->code );
    190190    }
    191191
     
    212212        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    213213        $this->assertIXRError( $result );
    214         $this->assertEquals( 401, $result->code );
     214        $this->assertSame( 401, $result->code );
    215215    }
    216216
     
    224224        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    225225        $this->assertNotIXRError( $result );
    226         $this->assertEquals( 'quote', get_post_format( $result ) );
     226        $this->assertSame( 'quote', get_post_format( $result ) );
    227227    }
    228228
     
    250250        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    251251        $this->assertIXRError( $result );
    252         $this->assertEquals( 401, $result->code );
     252        $this->assertSame( 401, $result->code );
    253253
    254254        $post2   = array(
     
    260260        $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) );
    261261        $this->assertIXRError( $result2 );
    262         $this->assertEquals( 401, $result2->code );
     262        $this->assertSame( 401, $result2->code );
    263263    }
    264264
     
    274274        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    275275        $this->assertIXRError( $result );
    276         $this->assertEquals( 403, $result->code );
     276        $this->assertSame( 403, $result->code );
    277277    }
    278278
     
    339339        $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) );
    340340        $this->assertIXRError( $result2 );
    341         $this->assertEquals( 401, $result2->code );
     341        $this->assertSame( 401, $result2->code );
    342342    }
    343343
     
    356356        $fetched_post = get_post( $result );
    357357        $this->assertStringMatchesFormat( '%d', $result );
    358         $this->assertEquals( current_time( 'Y-m-d' ), substr( $fetched_post->post_date, 0, 10 ) );
     358        $this->assertSame( current_time( 'Y-m-d' ), substr( $fetched_post->post_date, 0, 10 ) );
    359359    }
    360360
     
    373373        $fetched_post = get_post( $result );
    374374        $this->assertStringMatchesFormat( '%d', $result );
    375         $this->assertEquals( '0000-00-00', substr( $fetched_post->post_date_gmt, 0, 10 ) );
     375        $this->assertSame( '0000-00-00', substr( $fetched_post->post_date_gmt, 0, 10 ) );
    376376    }
    377377
     
    390390        $fetched_post = get_post( $result );
    391391        $this->assertStringMatchesFormat( '%d', $result );
    392         $this->assertEquals( $date_string, $fetched_post->post_date );
     392        $this->assertSame( $date_string, $fetched_post->post_date );
    393393    }
    394394
     
    407407        $fetched_post = get_post( $result );
    408408        $this->assertStringMatchesFormat( '%d', $result );
    409         $this->assertEquals( $date_string, $fetched_post->post_date_gmt );
     409        $this->assertSame( $date_string, $fetched_post->post_date_gmt );
    410410    }
    411411
     
    424424        $fetched_post = get_post( $result );
    425425        $this->assertStringMatchesFormat( '%d', $result );
    426         $this->assertEquals( $date_string, $fetched_post->post_date );
     426        $this->assertSame( $date_string, $fetched_post->post_date );
    427427    }
    428428
     
    441441        $fetched_post = get_post( $result );
    442442        $this->assertStringMatchesFormat( '%d', $result );
    443         $this->assertEquals( $date_string, $fetched_post->post_date_gmt );
     443        $this->assertSame( $date_string, $fetched_post->post_date_gmt );
    444444    }
    445445
Note: See TracChangeset for help on using the changeset viewer.