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

    r47122 r48937  
    1010        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'username', 'password', $post ) );
    1111        $this->assertIXRError( $result );
    12         $this->assertEquals( 403, $result->code );
     12        $this->assertSame( 403, $result->code );
    1313    }
    1414
     
    1919        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'subscriber', 'subscriber', $post ) );
    2020        $this->assertIXRError( $result );
    21         $this->assertEquals( 401, $result->code );
     21        $this->assertSame( 401, $result->code );
    2222    }
    2323
     
    2828        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
    2929        $this->assertIXRError( $result );
    30         $this->assertEquals( 500, $result->code );
    31         $this->assertEquals( 'Content, title, and excerpt are empty.', $result->message );
     30        $this->assertSame( 500, $result->code );
     31        $this->assertSame( 'Content, title, and excerpt are empty.', $result->message );
    3232    }
    3333
     
    7373        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'contributor', 'contributor', $post ) );
    7474        $this->assertIXRError( $result );
    75         $this->assertEquals( 401, $result->code );
     75        $this->assertSame( 401, $result->code );
    7676    }
    7777
     
    9898        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'contributor', 'contributor', $post ) );
    9999        $this->assertIXRError( $result );
    100         $this->assertEquals( 401, $result->code );
     100        $this->assertSame( 401, $result->code );
    101101    }
    102102
     
    113113        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
    114114        $this->assertIXRError( $result );
    115         $this->assertEquals( 404, $result->code );
     115        $this->assertSame( 404, $result->code );
    116116    }
    117117
     
    126126        $out = get_post( $result );
    127127        $this->assertEquals( $my_author_id, $out->post_author );
    128         $this->assertEquals( 'Test', $out->post_title );
     128        $this->assertSame( 'Test', $out->post_title );
    129129    }
    130130
     
    158158        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
    159159        $this->assertIXRError( $result );
    160         $this->assertEquals( 401, $result->code );
     160        $this->assertSame( 401, $result->code );
    161161    }
    162162
     
    173173
    174174        $out = get_post( $result );
    175         $this->assertEquals( 'Test', $out->post_title );
    176         $this->assertEquals( 'page', $out->post_type );
     175        $this->assertSame( 'Test', $out->post_title );
     176        $this->assertSame( 'page', $out->post_type );
    177177    }
    178178
     
    194194
    195195        $out = get_post( $result );
    196         $this->assertEquals( 'post', $out->post_type );
    197         $this->assertEquals( 'draft', $out->post_status );
    198         $this->assertEquals( '0000-00-00 00:00:00', $out->post_date_gmt );
     196        $this->assertSame( 'post', $out->post_type );
     197        $this->assertSame( 'draft', $out->post_status );
     198        $this->assertSame( '0000-00-00 00:00:00', $out->post_date_gmt );
    199199    }
    200200}
Note: See TracChangeset for help on using the changeset viewer.