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

    r46586 r48937  
    1717
    1818    public function test_get_weekday() {
    19         $this->assertEquals( __( 'Sunday' ), $this->locale->get_weekday( 0 ) );
    20         $this->assertEquals( __( 'Monday' ), $this->locale->get_weekday( 1 ) );
    21         $this->assertEquals( __( 'Tuesday' ), $this->locale->get_weekday( 2 ) );
    22         $this->assertEquals( __( 'Wednesday' ), $this->locale->get_weekday( 3 ) );
    23         $this->assertEquals( __( 'Thursday' ), $this->locale->get_weekday( 4 ) );
    24         $this->assertEquals( __( 'Friday' ), $this->locale->get_weekday( 5 ) );
    25         $this->assertEquals( __( 'Saturday' ), $this->locale->get_weekday( 6 ) );
     19        $this->assertSame( __( 'Sunday' ), $this->locale->get_weekday( 0 ) );
     20        $this->assertSame( __( 'Monday' ), $this->locale->get_weekday( 1 ) );
     21        $this->assertSame( __( 'Tuesday' ), $this->locale->get_weekday( 2 ) );
     22        $this->assertSame( __( 'Wednesday' ), $this->locale->get_weekday( 3 ) );
     23        $this->assertSame( __( 'Thursday' ), $this->locale->get_weekday( 4 ) );
     24        $this->assertSame( __( 'Friday' ), $this->locale->get_weekday( 5 ) );
     25        $this->assertSame( __( 'Saturday' ), $this->locale->get_weekday( 6 ) );
    2626    }
    2727
     
    3434
    3535    public function test_get_weekday_initial() {
    36         $this->assertEquals( __( 'S' ), $this->locale->get_weekday_initial( __( 'Sunday' ) ) );
    37         $this->assertEquals( __( 'M' ), $this->locale->get_weekday_initial( __( 'Monday' ) ) );
    38         $this->assertEquals( __( 'T' ), $this->locale->get_weekday_initial( __( 'Tuesday' ) ) );
    39         $this->assertEquals( __( 'W' ), $this->locale->get_weekday_initial( __( 'Wednesday' ) ) );
    40         $this->assertEquals( __( 'T' ), $this->locale->get_weekday_initial( __( 'Thursday' ) ) );
    41         $this->assertEquals( __( 'F' ), $this->locale->get_weekday_initial( __( 'Friday' ) ) );
    42         $this->assertEquals( __( 'S' ), $this->locale->get_weekday_initial( __( 'Saturday' ) ) );
     36        $this->assertSame( __( 'S' ), $this->locale->get_weekday_initial( __( 'Sunday' ) ) );
     37        $this->assertSame( __( 'M' ), $this->locale->get_weekday_initial( __( 'Monday' ) ) );
     38        $this->assertSame( __( 'T' ), $this->locale->get_weekday_initial( __( 'Tuesday' ) ) );
     39        $this->assertSame( __( 'W' ), $this->locale->get_weekday_initial( __( 'Wednesday' ) ) );
     40        $this->assertSame( __( 'T' ), $this->locale->get_weekday_initial( __( 'Thursday' ) ) );
     41        $this->assertSame( __( 'F' ), $this->locale->get_weekday_initial( __( 'Friday' ) ) );
     42        $this->assertSame( __( 'S' ), $this->locale->get_weekday_initial( __( 'Saturday' ) ) );
    4343    }
    4444
    4545    public function test_get_weekday_abbrev() {
    46         $this->assertEquals( __( 'Sun' ), $this->locale->get_weekday_abbrev( __( 'Sunday' ) ) );
    47         $this->assertEquals( __( 'Mon' ), $this->locale->get_weekday_abbrev( __( 'Monday' ) ) );
    48         $this->assertEquals( __( 'Tue' ), $this->locale->get_weekday_abbrev( __( 'Tuesday' ) ) );
    49         $this->assertEquals( __( 'Wed' ), $this->locale->get_weekday_abbrev( __( 'Wednesday' ) ) );
    50         $this->assertEquals( __( 'Thu' ), $this->locale->get_weekday_abbrev( __( 'Thursday' ) ) );
    51         $this->assertEquals( __( 'Fri' ), $this->locale->get_weekday_abbrev( __( 'Friday' ) ) );
    52         $this->assertEquals( __( 'Sat' ), $this->locale->get_weekday_abbrev( __( 'Saturday' ) ) );
     46        $this->assertSame( __( 'Sun' ), $this->locale->get_weekday_abbrev( __( 'Sunday' ) ) );
     47        $this->assertSame( __( 'Mon' ), $this->locale->get_weekday_abbrev( __( 'Monday' ) ) );
     48        $this->assertSame( __( 'Tue' ), $this->locale->get_weekday_abbrev( __( 'Tuesday' ) ) );
     49        $this->assertSame( __( 'Wed' ), $this->locale->get_weekday_abbrev( __( 'Wednesday' ) ) );
     50        $this->assertSame( __( 'Thu' ), $this->locale->get_weekday_abbrev( __( 'Thursday' ) ) );
     51        $this->assertSame( __( 'Fri' ), $this->locale->get_weekday_abbrev( __( 'Friday' ) ) );
     52        $this->assertSame( __( 'Sat' ), $this->locale->get_weekday_abbrev( __( 'Saturday' ) ) );
    5353    }
    5454
    5555    public function test_get_month() {
    56         $this->assertEquals( __( 'January' ), $this->locale->get_month( 1 ) );
    57         $this->assertEquals( __( 'February' ), $this->locale->get_month( 2 ) );
    58         $this->assertEquals( __( 'March' ), $this->locale->get_month( 3 ) );
    59         $this->assertEquals( __( 'April' ), $this->locale->get_month( 4 ) );
    60         $this->assertEquals( __( 'May' ), $this->locale->get_month( 5 ) );
    61         $this->assertEquals( __( 'June' ), $this->locale->get_month( 6 ) );
    62         $this->assertEquals( __( 'July' ), $this->locale->get_month( 7 ) );
    63         $this->assertEquals( __( 'August' ), $this->locale->get_month( 8 ) );
    64         $this->assertEquals( __( 'September' ), $this->locale->get_month( 9 ) );
    65         $this->assertEquals( __( 'October' ), $this->locale->get_month( 10 ) );
    66         $this->assertEquals( __( 'November' ), $this->locale->get_month( 11 ) );
    67         $this->assertEquals( __( 'December' ), $this->locale->get_month( 12 ) );
     56        $this->assertSame( __( 'January' ), $this->locale->get_month( 1 ) );
     57        $this->assertSame( __( 'February' ), $this->locale->get_month( 2 ) );
     58        $this->assertSame( __( 'March' ), $this->locale->get_month( 3 ) );
     59        $this->assertSame( __( 'April' ), $this->locale->get_month( 4 ) );
     60        $this->assertSame( __( 'May' ), $this->locale->get_month( 5 ) );
     61        $this->assertSame( __( 'June' ), $this->locale->get_month( 6 ) );
     62        $this->assertSame( __( 'July' ), $this->locale->get_month( 7 ) );
     63        $this->assertSame( __( 'August' ), $this->locale->get_month( 8 ) );
     64        $this->assertSame( __( 'September' ), $this->locale->get_month( 9 ) );
     65        $this->assertSame( __( 'October' ), $this->locale->get_month( 10 ) );
     66        $this->assertSame( __( 'November' ), $this->locale->get_month( 11 ) );
     67        $this->assertSame( __( 'December' ), $this->locale->get_month( 12 ) );
    6868    }
    6969
    7070    public function test_get_month_leading_zero() {
    71         $this->assertEquals( __( 'January' ), $this->locale->get_month( '01' ) );
    72         $this->assertEquals( __( 'February' ), $this->locale->get_month( '02' ) );
    73         $this->assertEquals( __( 'March' ), $this->locale->get_month( '03' ) );
    74         $this->assertEquals( __( 'April' ), $this->locale->get_month( '04' ) );
    75         $this->assertEquals( __( 'May' ), $this->locale->get_month( '05' ) );
    76         $this->assertEquals( __( 'June' ), $this->locale->get_month( '06' ) );
    77         $this->assertEquals( __( 'July' ), $this->locale->get_month( '07' ) );
    78         $this->assertEquals( __( 'August' ), $this->locale->get_month( '08' ) );
    79         $this->assertEquals( __( 'September' ), $this->locale->get_month( '09' ) );
     71        $this->assertSame( __( 'January' ), $this->locale->get_month( '01' ) );
     72        $this->assertSame( __( 'February' ), $this->locale->get_month( '02' ) );
     73        $this->assertSame( __( 'March' ), $this->locale->get_month( '03' ) );
     74        $this->assertSame( __( 'April' ), $this->locale->get_month( '04' ) );
     75        $this->assertSame( __( 'May' ), $this->locale->get_month( '05' ) );
     76        $this->assertSame( __( 'June' ), $this->locale->get_month( '06' ) );
     77        $this->assertSame( __( 'July' ), $this->locale->get_month( '07' ) );
     78        $this->assertSame( __( 'August' ), $this->locale->get_month( '08' ) );
     79        $this->assertSame( __( 'September' ), $this->locale->get_month( '09' ) );
    8080    }
    8181
    8282    public function test_get_month_abbrev() {
    83         $this->assertEquals( __( 'Jan' ), $this->locale->get_month_abbrev( __( 'January' ) ) );
    84         $this->assertEquals( __( 'Feb' ), $this->locale->get_month_abbrev( __( 'February' ) ) );
    85         $this->assertEquals( __( 'Mar' ), $this->locale->get_month_abbrev( __( 'March' ) ) );
    86         $this->assertEquals( __( 'Apr' ), $this->locale->get_month_abbrev( __( 'April' ) ) );
    87         $this->assertEquals( __( 'May' ), $this->locale->get_month_abbrev( __( 'May' ) ) );
    88         $this->assertEquals( __( 'Jun' ), $this->locale->get_month_abbrev( __( 'June' ) ) );
    89         $this->assertEquals( __( 'Jul' ), $this->locale->get_month_abbrev( __( 'July' ) ) );
    90         $this->assertEquals( __( 'Aug' ), $this->locale->get_month_abbrev( __( 'August' ) ) );
    91         $this->assertEquals( __( 'Sep' ), $this->locale->get_month_abbrev( __( 'September' ) ) );
    92         $this->assertEquals( __( 'Oct' ), $this->locale->get_month_abbrev( __( 'October' ) ) );
    93         $this->assertEquals( __( 'Nov' ), $this->locale->get_month_abbrev( __( 'November' ) ) );
    94         $this->assertEquals( __( 'Dec' ), $this->locale->get_month_abbrev( __( 'December' ) ) );
     83        $this->assertSame( __( 'Jan' ), $this->locale->get_month_abbrev( __( 'January' ) ) );
     84        $this->assertSame( __( 'Feb' ), $this->locale->get_month_abbrev( __( 'February' ) ) );
     85        $this->assertSame( __( 'Mar' ), $this->locale->get_month_abbrev( __( 'March' ) ) );
     86        $this->assertSame( __( 'Apr' ), $this->locale->get_month_abbrev( __( 'April' ) ) );
     87        $this->assertSame( __( 'May' ), $this->locale->get_month_abbrev( __( 'May' ) ) );
     88        $this->assertSame( __( 'Jun' ), $this->locale->get_month_abbrev( __( 'June' ) ) );
     89        $this->assertSame( __( 'Jul' ), $this->locale->get_month_abbrev( __( 'July' ) ) );
     90        $this->assertSame( __( 'Aug' ), $this->locale->get_month_abbrev( __( 'August' ) ) );
     91        $this->assertSame( __( 'Sep' ), $this->locale->get_month_abbrev( __( 'September' ) ) );
     92        $this->assertSame( __( 'Oct' ), $this->locale->get_month_abbrev( __( 'October' ) ) );
     93        $this->assertSame( __( 'Nov' ), $this->locale->get_month_abbrev( __( 'November' ) ) );
     94        $this->assertSame( __( 'Dec' ), $this->locale->get_month_abbrev( __( 'December' ) ) );
    9595    }
    9696
    9797    public function test_get_meridiem() {
    98         $this->assertEquals( __( 'am' ), $this->locale->get_meridiem( 'am' ) );
    99         $this->assertEquals( __( 'AM' ), $this->locale->get_meridiem( 'AM' ) );
    100         $this->assertEquals( __( 'pm' ), $this->locale->get_meridiem( 'pm' ) );
    101         $this->assertEquals( __( 'PM' ), $this->locale->get_meridiem( 'PM' ) );
     98        $this->assertSame( __( 'am' ), $this->locale->get_meridiem( 'am' ) );
     99        $this->assertSame( __( 'AM' ), $this->locale->get_meridiem( 'AM' ) );
     100        $this->assertSame( __( 'pm' ), $this->locale->get_meridiem( 'pm' ) );
     101        $this->assertSame( __( 'PM' ), $this->locale->get_meridiem( 'PM' ) );
    102102    }
    103103
Note: See TracChangeset for help on using the changeset viewer.