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

    r46586 r48937  
    3434        $rfc3339  = $datetime->format( DATE_RFC3339 );
    3535
    36         $this->assertEquals( 0, date_i18n( 'U', 0 ) );
    37         $this->assertEquals( $rfc3339, date_i18n( DATE_RFC3339, 0 ) );
     36        $this->assertSame( 0, date_i18n( 'U', 0 ) );
     37        $this->assertSame( $rfc3339, date_i18n( DATE_RFC3339, 0 ) );
    3838    }
    3939
     
    4343
    4444    public function test_should_use_custom_timestamp() {
    45         $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
     45        $this->assertSame( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
    4646    }
    4747
     
    6565        update_option( 'timezone_string', 'America/Regina' );
    6666
    67         $this->assertEquals( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
     67        $this->assertSame( '2012-12-01 00:00:00', date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) );
    6868    }
    6969
     
    8888        $GLOBALS['wp_locale'] = $original_locale;
    8989
    90         $this->assertEquals( $expected, $actual );
     90        $this->assertSame( $expected, $actual );
    9191    }
    9292
     
    9494        update_option( 'timezone_string', 'America/Regina' );
    9595
    96         $this->assertEquals( '2012-12-01 00:00:00 CST -06:00 America/Regina', date_i18n( 'Y-m-d H:i:s T P e', strtotime( '2012-12-01 00:00:00' ) ) );
     96        $this->assertSame( '2012-12-01 00:00:00 CST -06:00 America/Regina', date_i18n( 'Y-m-d H:i:s T P e', strtotime( '2012-12-01 00:00:00' ) ) );
    9797    }
    9898
     
    111111        $datetime = new DateTime( $datetime->format( 'P' ) );
    112112
    113         $this->assertEquals( $datetime->format( $timezone_formats ), date_i18n( $timezone_formats ) );
     113        $this->assertSame( $datetime->format( $timezone_formats ), date_i18n( $timezone_formats ) );
    114114    }
    115115
     
    123123
    124124        $this->assertEquals( strtotime( date_i18n( $full ) ), strtotime( date_i18n( $short ) ), 'The dates should be equal', 2 );
    125         $this->assertEquals( $short, date_i18n( '\\' . $short ) );
     125        $this->assertSame( $short, date_i18n( '\\' . $short ) );
    126126    }
    127127
     
    151151        $this->assertEquals( $wp_timestamp, date_i18n( 'U' ), 'The dates should be equal', 2 );
    152152        $this->assertEquals( $timestamp, date_i18n( 'U', false, true ), 'The dates should be equal', 2 );
    153         $this->assertEquals( $wp_timestamp, date_i18n( 'U', $wp_timestamp ) );
     153        $this->assertSame( $wp_timestamp, date_i18n( 'U', $wp_timestamp ) );
    154154    }
    155155
     
    160160        update_option( 'timezone_string', 'America/Regina' );
    161161
    162         $this->assertEquals( gmdate( 'B' ), date_i18n( 'B' ) );
     162        $this->assertSame( gmdate( 'B' ), date_i18n( 'B' ) );
    163163    }
    164164
     
    169169        $format = 'D | \D | \\D | \\\D | \\\\D | \\\\\D | \\\\\\D';
    170170
    171         $this->assertEquals( gmdate( $format ), date_i18n( $format ) );
     171        $this->assertSame( gmdate( $format ), date_i18n( $format ) );
    172172    }
    173173
     
    188188        $format       = 'I ' . DATE_RFC3339;
    189189
    190         $this->assertEquals( $datetime->format( $format ), date_i18n( $format, $wp_timestamp ) );
     190        $this->assertSame( $datetime->format( $format ), date_i18n( $format, $wp_timestamp ) );
    191191    }
    192192
Note: See TracChangeset for help on using the changeset viewer.