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/formatting/date.php

    r46586 r48937  
    1616        $local = '2012-01-01 12:34:56';
    1717        $gmt   = $local;
    18         $this->assertEquals( $local, get_date_from_gmt( $gmt ) );
     18        $this->assertSame( $local, get_date_from_gmt( $gmt ) );
    1919    }
    2020
     
    2828        $gmt   = '2012-06-01 12:34:56';
    2929        $local = '2012-06-01 13:34:56';
    30         $this->assertEquals( $local, get_date_from_gmt( $gmt ) );
     30        $this->assertSame( $local, get_date_from_gmt( $gmt ) );
    3131    }
    3232
     
    3838        $local = '2012-01-01 12:34:56';
    3939        $gmt   = $local;
    40         $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     40        $this->assertSame( $gmt, get_gmt_from_date( $local ) );
    4141    }
    4242
     
    4848        $local = '2012-06-01 12:34:56';
    4949        $gmt   = '2012-06-01 11:34:56';
    50         $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     50        $this->assertSame( $gmt, get_gmt_from_date( $local ) );
    5151    }
    5252
     
    5757        $local = '2012-01-01 12:34:56';
    5858        $gmt   = $local;
    59         $this->assertEquals( $gmt, get_date_from_gmt( $local ) );
     59        $this->assertSame( $gmt, get_date_from_gmt( $local ) );
    6060    }
    6161
     
    6666        $gmt  = '2012-12-01 00:00:00';
    6767        $date = '2012-12-01';
    68         $this->assertEquals( $gmt, get_gmt_from_date( $date ) );
     68        $this->assertSame( $gmt, get_gmt_from_date( $date ) );
    6969    }
    7070
     
    7676        $local = '2012-12-01';
    7777        $gmt   = '2012-12-01 00:00:00';
    78         $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     78        $this->assertSame( $gmt, get_gmt_from_date( $local ) );
    7979    }
    8080
     
    111111        $mysql_local = $local->format( 'Y-m-d H:i:s' );
    112112
    113         $this->assertEquals( $utc->format( DATE_RFC3339 ), get_gmt_from_date( $mysql_local, DATE_RFC3339 ) );
     113        $this->assertSame( $utc->format( DATE_RFC3339 ), get_gmt_from_date( $mysql_local, DATE_RFC3339 ) );
    114114    }
    115115
     
    127127        $mysql_utc = $utc->format( 'Y-m-d H:i:s' );
    128128
    129         $this->assertEquals( $local->format( DATE_RFC3339 ), get_date_from_gmt( $mysql_utc, DATE_RFC3339 ) );
     129        $this->assertSame( $local->format( DATE_RFC3339 ), get_date_from_gmt( $mysql_utc, DATE_RFC3339 ) );
    130130    }
    131131
     
    145145        $utc   = $local->setTimezone( new DateTimeZone( 'UTC' ) );
    146146
    147         $this->assertEquals(
     147        $this->assertSame(
    148148            $local->format( 'Y-m-d H:i:s' ),
    149149            iso8601_to_datetime( $local->format( $format ) ),
    150150            'Local time from local time.'
    151151        );
    152         $this->assertEquals(
     152        $this->assertSame(
    153153            $utc->format( 'Y-m-d H:i:s' ),
    154154            iso8601_to_datetime( $local->format( $format ), 'gmt' ),
     
    156156        );
    157157
    158         $this->assertEquals(
     158        $this->assertSame(
    159159            $local->format( 'Y-m-d H:i:s' ),
    160160            iso8601_to_datetime( $local->format( $format_no_tz ) ),
    161161            'Local time from local time w/o timezone.'
    162162        );
    163         $this->assertEquals(
     163        $this->assertSame(
    164164            $utc->format( 'Y-m-d H:i:s' ),
    165165            iso8601_to_datetime( $local->format( $format_no_tz ), 'gmt' ),
     
    167167        );
    168168
    169         $this->assertEquals(
     169        $this->assertSame(
    170170            $local->format( 'Y-m-d H:i:s' ),
    171171            iso8601_to_datetime( $utc->format( $format ) ),
    172172            'Local time from UTC time.'
    173173        );
    174         $this->assertEquals(
     174        $this->assertSame(
    175175            $utc->format( 'Y-m-d H:i:s' ),
    176176            iso8601_to_datetime( $utc->format( $format ), 'gmt' ),
     
    178178        );
    179179
    180         $this->assertEquals(
     180        $this->assertSame(
    181181            $local->format( 'Y-m-d H:i:s' ),
    182182            iso8601_to_datetime( $utc->format( $format_no_tz ) . 'Z' ),
    183183            'Local time from UTC w/ Z timezone.'
    184184        );
    185         $this->assertEquals(
     185        $this->assertSame(
    186186            $utc->format( 'Y-m-d H:i:s' ),
    187187            iso8601_to_datetime( $utc->format( $format_no_tz ) . 'Z', 'gmt' ),
Note: See TracChangeset for help on using the changeset viewer.