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/formatting/balanceTags.php

    r47122 r48937  
    155155        $normalized = strtolower( $tag );
    156156
    157         $this->assertEquals( "<$normalized>inside</$normalized>", balanceTags( "<$tag>inside", true ) );
     157        $this->assertSame( "<$normalized>inside</$normalized>", balanceTags( "<$tag>inside", true ) );
    158158    }
    159159
     
    163163     */
    164164    function test_detects_supported_custom_element_tag_names( $tag ) {
    165         $this->assertEquals( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
     165        $this->assertSame( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
    166166    }
    167167
     
    171171     */
    172172    function test_ignores_invalid_tag_names( $input, $output ) {
    173         $this->assertEquals( $output, balanceTags( $input, true ) );
     173        $this->assertSame( $output, balanceTags( $input, true ) );
    174174    }
    175175
     
    179179     */
    180180    function test_ignores_unsupported_custom_tag_names( $tag ) {
    181         $this->assertEquals( "<$tag>inside", balanceTags( "<$tag>inside", true ) );
     181        $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) );
    182182    }
    183183
     
    187187     */
    188188    function test_detects_supported_invalid_tag_names( $tag ) {
    189         $this->assertEquals( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
     189        $this->assertSame( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
    190190    }
    191191
     
    197197     */
    198198    function test_selfcloses_unclosed_known_single_tags( $tag ) {
    199         $this->assertEquals( "<$tag />", balanceTags( "<$tag>", true ) );
     199        $this->assertSame( "<$tag />", balanceTags( "<$tag>", true ) );
    200200    }
    201201
     
    208208     */
    209209    function test_selfcloses_known_single_tags_having_closing_tag( $tag ) {
    210         $this->assertEquals( "<$tag />", balanceTags( "<$tag></$tag>", true ) );
     210        $this->assertSame( "<$tag />", balanceTags( "<$tag></$tag>", true ) );
    211211    }
    212212
     
    233233
    234234        foreach ( $inputs as $key => $input ) {
    235             $this->assertEquals( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
     235            $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    236236        }
    237237    }
     
    248248
    249249        foreach ( $inputs as $key => $input ) {
    250             $this->assertEquals( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
     250            $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    251251        }
    252252    }
     
    261261
    262262        foreach ( $inputs as $key => $input ) {
    263             $this->assertEquals( $inputs[ $key ], balanceTags( $inputs[ $key ], true ) );
     263            $this->assertSame( $inputs[ $key ], balanceTags( $inputs[ $key ], true ) );
    264264        }
    265265    }
     
    281281
    282282        foreach ( $inputs as $key => $input ) {
    283             $this->assertEquals( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
     283            $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    284284        }
    285285    }
     
    295295
    296296        foreach ( $inputs as $key => $input ) {
    297             $this->assertEquals( $inputs[ $key ], balanceTags( $inputs[ $key ], true ) );
     297            $this->assertSame( $inputs[ $key ], balanceTags( $inputs[ $key ], true ) );
    298298        }
    299299    }
     
    304304    function test_allows_immediately_nested_object_tags() {
    305305        $object = '<object id="obj1"><param name="param1"/><object id="obj2"><param name="param2"/></object></object>';
    306         $this->assertEquals( $object, balanceTags( $object, true ) );
     306        $this->assertSame( $object, balanceTags( $object, true ) );
    307307    }
    308308
     
    318318
    319319        foreach ( $inputs as $key => $input ) {
    320             $this->assertEquals( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
     320            $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    321321        }
    322322    }
     
    333333
    334334        foreach ( $inputs as $key => $input ) {
    335             $this->assertEquals( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
     335            $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    336336        }
    337337    }
     
    354354
    355355        foreach ( $inputs as $key => $input ) {
    356             $this->assertEquals( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
     356            $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    357357        }
    358358    }
     
    373373
    374374        foreach ( $inputs as $key => $input ) {
    375             $this->assertEquals( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
     375            $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    376376        }
    377377    }
     
    439439     */
    440440    public function test_custom_elements( $source, $expected ) {
    441         $this->assertEquals( $expected, balanceTags( $source, true ) );
     441        $this->assertSame( $expected, balanceTags( $source, true ) );
    442442    }
    443443}
Note: See TracChangeset for help on using the changeset viewer.