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/functions/numberFormatI18n.php

    r47780 r48937  
    1717        $GLOBALS['wp_locale'] = $locale;
    1818
    19         $this->assertEquals( '123,457', $actual_1 );
    20         $this->assertEquals( '123,456.7890', $actual_2 );
     19        $this->assertSame( '123,457', $actual_1 );
     20        $this->assertSame( '123,456.7890', $actual_2 );
    2121    }
    2222
     
    3434        $GLOBALS['wp_locale']->number_format['thousands_sep'] = $thousands_sep;
    3535
    36         $this->assertEquals( '123^457', $actual_1 );
    37         $this->assertEquals( '123^456@7890', $actual_2 );
     36        $this->assertSame( '123^457', $actual_1 );
     37        $this->assertSame( '123^456@7890', $actual_2 );
    3838    }
    3939
    4040    public function test_should_default_to_en_us_format() {
    41         $this->assertEquals( '123,457', number_format_i18n( 123456.789, 0 ) );
    42         $this->assertEquals( '123,456.7890', number_format_i18n( 123456.789, 4 ) );
     41        $this->assertSame( '123,457', number_format_i18n( 123456.789, 0 ) );
     42        $this->assertSame( '123,456.7890', number_format_i18n( 123456.789, 4 ) );
    4343    }
    4444
    4545    public function test_should_handle_negative_precision() {
    46         $this->assertEquals( '123,457', number_format_i18n( 123456.789, 0 ) );
    47         $this->assertEquals( '123,456.7890', number_format_i18n( 123456.789, -4 ) );
     46        $this->assertSame( '123,457', number_format_i18n( 123456.789, 0 ) );
     47        $this->assertSame( '123,456.7890', number_format_i18n( 123456.789, -4 ) );
    4848    }
    4949}
Note: See TracChangeset for help on using the changeset viewer.