Make WordPress Core


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

    r48433 r48937  
    1111    function test_preserves_original_datatype() {
    1212
    13         $this->assertEquals( true, stripslashes_deep( true ) );
    14         $this->assertEquals( false, stripslashes_deep( false ) );
    15         $this->assertEquals( 4, stripslashes_deep( 4 ) );
    16         $this->assertEquals( 'foo', stripslashes_deep( 'foo' ) );
     13        $this->assertTrue( stripslashes_deep( true ) );
     14        $this->assertFalse( stripslashes_deep( false ) );
     15        $this->assertSame( 4, stripslashes_deep( 4 ) );
     16        $this->assertSame( 'foo', stripslashes_deep( 'foo' ) );
    1717        $arr      = array(
    1818            'a' => true,
     
    2222        );
    2323        $arr['e'] = $arr; // Add a sub-array.
    24         $this->assertEquals( $arr, stripslashes_deep( $arr ) ); // Keyed array.
    25         $this->assertEquals( array_values( $arr ), stripslashes_deep( array_values( $arr ) ) ); // Non-keyed.
     24        $this->assertSame( $arr, stripslashes_deep( $arr ) ); // Keyed array.
     25        $this->assertSame( array_values( $arr ), stripslashes_deep( array_values( $arr ) ) ); // Non-keyed.
    2626
    2727        $obj = new stdClass;
     
    2929            $obj->$k = $v;
    3030        }
    31         $this->assertEquals( $obj, stripslashes_deep( $obj ) );
     31        $this->assertSame( $obj, stripslashes_deep( $obj ) );
    3232    }
    3333
     
    3535        $old = "I can\'t see, isn\'t that it?";
    3636        $new = "I can't see, isn't that it?";
    37         $this->assertEquals( $new, stripslashes_deep( $old ) );
    38         $this->assertEquals( $new, stripslashes_deep( "I can\\'t see, isn\\'t that it?" ) );
    39         $this->assertEquals( array( 'a' => $new ), stripslashes_deep( array( 'a' => $old ) ) ); // Keyed array.
    40         $this->assertEquals( array( $new ), stripslashes_deep( array( $old ) ) ); // Non-keyed.
     37        $this->assertSame( $new, stripslashes_deep( $old ) );
     38        $this->assertSame( $new, stripslashes_deep( "I can\\'t see, isn\\'t that it?" ) );
     39        $this->assertSame( array( 'a' => $new ), stripslashes_deep( array( 'a' => $old ) ) ); // Keyed array.
     40        $this->assertSame( array( $new ), stripslashes_deep( array( $old ) ) ); // Non-keyed.
    4141
    4242        $obj_old    = new stdClass;
     
    4949    function test_permits_escaped_slash() {
    5050        $txt = "I can't see, isn\'t that it?";
    51         $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\'t that it?" ) );
    52         $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\\\'t that it?" ) );
     51        $this->assertSame( $txt, stripslashes_deep( "I can\'t see, isn\\\'t that it?" ) );
     52        $this->assertSame( $txt, stripslashes_deep( "I can\'t see, isn\\\\\'t that it?" ) );
    5353    }
    5454}
Note: See TracChangeset for help on using the changeset viewer.