WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (3 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/pomo/mo.php

    r46586 r48937  
    99        $mo = new MO();
    1010        $mo->import_from_file( DIR_TESTDATA . '/pomo/simple.mo' );
    11         $this->assertEquals(
     11        $this->assertSame(
    1212            array(
    1313                'Project-Id-Version'   => 'WordPress 2.6-bleeding',
     
    1616            $mo->headers
    1717        );
    18         $this->assertEquals( 2, count( $mo->entries ) );
    19         $this->assertEquals( array( 'dyado' ), $mo->entries['baba']->translations );
    20         $this->assertEquals( array( 'yes' ), $mo->entries["kuku\nruku"]->translations );
     18        $this->assertSame( 2, count( $mo->entries ) );
     19        $this->assertSame( array( 'dyado' ), $mo->entries['baba']->translations );
     20        $this->assertSame( array( 'yes' ), $mo->entries["kuku\nruku"]->translations );
    2121    }
    2222
     
    2424        $mo = new MO();
    2525        $mo->import_from_file( DIR_TESTDATA . '/pomo/plural.mo' );
    26         $this->assertEquals( 1, count( $mo->entries ) );
    27         $this->assertEquals( array( 'oney dragoney', 'twoey dragoney', 'manyey dragoney', 'manyeyey dragoney', 'manyeyeyey dragoney' ), $mo->entries['one dragon']->translations );
     26        $this->assertSame( 1, count( $mo->entries ) );
     27        $this->assertSame( array( 'oney dragoney', 'twoey dragoney', 'manyey dragoney', 'manyeyey dragoney', 'manyeyeyey dragoney' ), $mo->entries['one dragon']->translations );
    2828
    29         $this->assertEquals( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
    30         $this->assertEquals( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 2 ) );
    31         $this->assertEquals( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', -8 ) );
     29        $this->assertSame( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
     30        $this->assertSame( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 2 ) );
     31        $this->assertSame( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', -8 ) );
    3232
    3333        $mo->set_header( 'Plural-Forms', 'nplurals=5; plural=0' );
    34         $this->assertEquals( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
    35         $this->assertEquals( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 2 ) );
    36         $this->assertEquals( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', -8 ) );
     34        $this->assertSame( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
     35        $this->assertSame( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 2 ) );
     36        $this->assertSame( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', -8 ) );
    3737
    3838        $mo->set_header( 'Plural-Forms', 'nplurals=5; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;' );
    39         $this->assertEquals( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
    40         $this->assertEquals( 'manyey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 11 ) );
    41         $this->assertEquals( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 3 ) );
     39        $this->assertSame( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
     40        $this->assertSame( 'manyey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 11 ) );
     41        $this->assertSame( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 3 ) );
    4242
    4343        $mo->set_header( 'Plural-Forms', 'nplurals=2; plural=n !=1;' );
    44         $this->assertEquals( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
    45         $this->assertEquals( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 2 ) );
    46         $this->assertEquals( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', -8 ) );
     44        $this->assertSame( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) );
     45        $this->assertSame( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 2 ) );
     46        $this->assertSame( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', -8 ) );
    4747    }
    4848
     
    5050        $mo = new MO();
    5151        $mo->import_from_file( DIR_TESTDATA . '/pomo/context.mo' );
    52         $this->assertEquals( 2, count( $mo->entries ) );
     52        $this->assertSame( 2, count( $mo->entries ) );
    5353        $plural_entry = new Translation_Entry(
    5454            array(
     
    6060        );
    6161        $this->assertEquals( $plural_entry, $mo->entries[ $plural_entry->key() ] );
    62         $this->assertEquals( 'dragonland', $mo->entries[ $plural_entry->key() ]->context );
     62        $this->assertSame( 'dragonland', $mo->entries[ $plural_entry->key() ]->context );
    6363
    6464        $single_entry = new Translation_Entry(
     
    7070        );
    7171        $this->assertEquals( $single_entry, $mo->entries[ $single_entry->key() ] );
    72         $this->assertEquals( 'not so dragon', $mo->entries[ $single_entry->key() ]->context );
     72        $this->assertSame( 'not so dragon', $mo->entries[ $single_entry->key() ]->context );
    7373
    7474    }
     
    8282        $guest->add_entry( new Translation_Entry( array( 'singular' => 'red' ) ) );
    8383        $host->merge_with( $guest );
    84         $this->assertEquals( 3, count( $host->entries ) );
    85         $this->assertEquals( array(), array_diff( array( 'pink', 'green', 'red' ), array_keys( $host->entries ) ) );
     84        $this->assertSame( 3, count( $host->entries ) );
     85        $this->assertSame( array(), array_diff( array( 'pink', 'green', 'red' ), array_keys( $host->entries ) ) );
    8686    }
    8787
     
    138138        $again->import_from_file( $temp_fn );
    139139
    140         $this->assertEquals( count( $entries ), count( $again->entries ) );
     140        $this->assertSame( count( $entries ), count( $again->entries ) );
    141141        foreach ( $entries as $entry ) {
    142142            $this->assertEquals( $entry, $again->entries[ $entry->key() ] );
     
    160160        $again->import_from_file( $temp_fn );
    161161
    162         $this->assertEquals( 0, count( $again->entries ) );
     162        $this->assertSame( 0, count( $again->entries ) );
    163163    }
    164164
     
    166166        $mo = new MO();
    167167        $mo->import_from_file( DIR_TESTDATA . '/pomo/bad_nplurals.mo' );
    168         $this->assertEquals( '%d foro', $mo->translate_plural( '%d forum', '%d forums', 1 ) );
    169         $this->assertEquals( '%d foros', $mo->translate_plural( '%d forum', '%d forums', 2 ) );
    170         $this->assertEquals( '%d foros', $mo->translate_plural( '%d forum', '%d forums', -1 ) );
     168        $this->assertSame( '%d foro', $mo->translate_plural( '%d forum', '%d forums', 1 ) );
     169        $this->assertSame( '%d foros', $mo->translate_plural( '%d forum', '%d forums', 2 ) );
     170        $this->assertSame( '%d foros', $mo->translate_plural( '%d forum', '%d forums', -1 ) );
    171171    }
    172172
     
    185185        $mo = new MO();
    186186        $mo->import_from_file( DIR_TESTDATA . '/pomo/overload.mo' );
    187         $this->assertEquals( array( 'Табло' ), $mo->entries['Dashboard']->translations );
     187        $this->assertSame( array( 'Табло' ), $mo->entries['Dashboard']->translations );
    188188    }
    189189
    190190    function test_load_pot_file() {
    191191        $mo = new MO();
    192         $this->assertEquals( false, $mo->import_from_file( DIR_TESTDATA . '/pomo/mo.pot' ) );
     192        $this->assertFalse( $mo->import_from_file( DIR_TESTDATA . '/pomo/mo.pot' ) );
    193193    }
    194194}
Note: See TracChangeset for help on using the changeset viewer.