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

    r46586 r48937  
    2424
    2525        $this->assertNotEmpty( $nooped_plural['domain'] );
    26         $this->assertEquals( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) );
    27         $this->assertEquals( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) );
    28         $this->assertEquals( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) );
     26        $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) );
     27        $this->assertSame( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) );
     28        $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) );
    2929    }
    3030
     
    3838        $this->assertNotEmpty( $nooped_plural['domain'] );
    3939        $this->assertNotEmpty( $nooped_plural['context'] );
    40         $this->assertEquals( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) );
    41         $this->assertEquals( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) );
    42         $this->assertEquals( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) );
     40        $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) );
     41        $this->assertSame( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) );
     42        $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) );
    4343    }
    4444
     
    4747     */
    4848    function test_before_last_bar() {
    49         $this->assertEquals( 'no-bar-at-all', before_last_bar( 'no-bar-at-all' ) );
    50         $this->assertEquals( 'before-last-bar', before_last_bar( 'before-last-bar|after-bar' ) );
    51         $this->assertEquals( 'first-before-bar|second-before-bar', before_last_bar( 'first-before-bar|second-before-bar|after-last-bar' ) );
     49        $this->assertSame( 'no-bar-at-all', before_last_bar( 'no-bar-at-all' ) );
     50        $this->assertSame( 'before-last-bar', before_last_bar( 'before-last-bar|after-bar' ) );
     51        $this->assertSame( 'first-before-bar|second-before-bar', before_last_bar( 'first-before-bar|second-before-bar|after-last-bar' ) );
    5252    }
    5353
     
    6363
    6464        $array = get_available_languages( DIR_TESTDATA . '/languages/' );
    65         $this->assertEquals( array( 'de_DE', 'en_GB', 'es_ES', 'ja_JP' ), $array );
     65        $this->assertSame( array( 'de_DE', 'en_GB', 'es_ES', 'ja_JP' ), $array );
    6666    }
    6767
     
    7777        $this->assertNotEmpty( $installed_translations['default']['en_GB'] );
    7878        $data_en_gb = $installed_translations['default']['en_GB'];
    79         $this->assertEquals( '2016-10-26 00:01+0200', $data_en_gb['PO-Revision-Date'] );
    80         $this->assertEquals( 'Development (4.4.x)', $data_en_gb['Project-Id-Version'] );
    81         $this->assertEquals( 'Poedit 1.8.10', $data_en_gb['X-Generator'] );
     79        $this->assertSame( '2016-10-26 00:01+0200', $data_en_gb['PO-Revision-Date'] );
     80        $this->assertSame( 'Development (4.4.x)', $data_en_gb['Project-Id-Version'] );
     81        $this->assertSame( 'Poedit 1.8.10', $data_en_gb['X-Generator'] );
    8282
    8383        $this->assertNotEmpty( $installed_translations['admin']['es_ES'] );
    8484        $data_es_es = $installed_translations['admin']['es_ES'];
    85         $this->assertEquals( '2016-10-25 18:29+0200', $data_es_es['PO-Revision-Date'] );
    86         $this->assertEquals( 'Administration', $data_es_es['Project-Id-Version'] );
    87         $this->assertEquals( 'Poedit 1.8.10', $data_es_es['X-Generator'] );
     85        $this->assertSame( '2016-10-25 18:29+0200', $data_es_es['PO-Revision-Date'] );
     86        $this->assertSame( 'Administration', $data_es_es['Project-Id-Version'] );
     87        $this->assertSame( 'Poedit 1.8.10', $data_es_es['X-Generator'] );
    8888    }
    8989
Note: See TracChangeset for help on using the changeset viewer.