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/pomo/translations.php

    r47122 r48937  
    1212        $po     = new Translations();
    1313        $po->add_entry( $entry );
    14         $this->assertEquals( array( $entry->key() => $entry ), $po->entries );
     14        $this->assertSame( array( $entry->key() => $entry ), $po->entries );
    1515        // Add the same entry more than once.
    1616        // We do not need to test proper key generation here, see test_key().
    1717        $po->add_entry( $entry );
    1818        $po->add_entry( $entry );
    19         $this->assertEquals( array( $entry->key() => $entry ), $po->entries );
     19        $this->assertSame( array( $entry->key() => $entry ), $po->entries );
    2020        $po->add_entry( $entry2 );
    21         $this->assertEquals(
     21        $this->assertSame(
    2222            array(
    2323                $entry->key()  => $entry,
     
    2727        );
    2828        // Add empty entry.
    29         $this->assertEquals( false, $po->add_entry( $empty ) );
    30         $this->assertEquals(
     29        $this->assertFalse( $po->add_entry( $empty ) );
     30        $this->assertSame(
    3131            array(
    3232                $entry->key()  => $entry,
     
    4040        $po->add_entry( array( 'singular' => 'baba' ) );
    4141        $entries = array_values( $po->entries );
    42         $this->assertEquals( $entry->key(), $entries[0]->key() );
     42        $this->assertSame( $entry->key(), $entries[0]->key() );
    4343    }
    4444
     
    6060        $domain->add_entry( $entry1 );
    6161        $domain->add_entry( $entry2 );
    62         $this->assertEquals( 'babax', $domain->translate( 'baba' ) );
    63         $this->assertEquals( 'babay', $domain->translate( 'baba', 'x' ) );
    64         $this->assertEquals( 'baba', $domain->translate( 'baba', 'y' ) );
    65         $this->assertEquals( 'babaz', $domain->translate( 'babaz' ) );
     62        $this->assertSame( 'babax', $domain->translate( 'baba' ) );
     63        $this->assertSame( 'babay', $domain->translate( 'baba', 'x' ) );
     64        $this->assertSame( 'baba', $domain->translate( 'baba', 'y' ) );
     65        $this->assertSame( 'babaz', $domain->translate( 'babaz' ) );
    6666    }
    6767
     
    9292        $domain->add_entry( $entry_toomany );
    9393        $domain->add_entry( $entry_2 );
    94         $this->assertEquals( 'other', $domain->translate_plural( 'other', 'others', 1 ) );
    95         $this->assertEquals( 'others', $domain->translate_plural( 'other', 'others', 111 ) );
     94        $this->assertSame( 'other', $domain->translate_plural( 'other', 'others', 1 ) );
     95        $this->assertSame( 'others', $domain->translate_plural( 'other', 'others', 111 ) );
    9696        // Too few translations + cont logic.
    97         $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', 2 ) );
    98         $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', 0 ) );
    99         $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', -1 ) );
    100         $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', 999 ) );
     97        $this->assertSame( 'babas', $domain->translate_plural( 'baba', 'babas', 2 ) );
     98        $this->assertSame( 'babas', $domain->translate_plural( 'baba', 'babas', 0 ) );
     99        $this->assertSame( 'babas', $domain->translate_plural( 'baba', 'babas', -1 ) );
     100        $this->assertSame( 'babas', $domain->translate_plural( 'baba', 'babas', 999 ) );
    101101        // Proper.
    102         $this->assertEquals( 'dyadox', $domain->translate_plural( 'dyado', 'dyados', 1 ) );
    103         $this->assertEquals( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', 0 ) );
    104         $this->assertEquals( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', 18881 ) );
    105         $this->assertEquals( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', -18881 ) );
     102        $this->assertSame( 'dyadox', $domain->translate_plural( 'dyado', 'dyados', 1 ) );
     103        $this->assertSame( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', 0 ) );
     104        $this->assertSame( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', 18881 ) );
     105        $this->assertSame( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', -18881 ) );
    106106    }
    107107
     
    123123        $domain->add_entry( $entry_digit_2 );
    124124        $dummy_translation = new Translations;
    125         $this->assertEquals( '1', $domain->translate( '1' ) );
     125        $this->assertSame( '1', $domain->translate( '1' ) );
    126126        $domain->merge_with( $dummy_translation );
    127         $this->assertEquals( '1', $domain->translate( '1' ) );
     127        $this->assertSame( '1', $domain->translate( '1' ) );
    128128    }
    129129
Note: See TracChangeset for help on using the changeset viewer.