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

    r48442 r48937  
    5858        $old = "I can't see, isn't that it?";
    5959        $new = "I can\'t see, isn\'t that it?";
    60         $this->assertEquals( $new, wp_slash( $old ) );
    61         $this->assertEquals( "I can\\\\\'t see, isn\\\\\'t that it?", wp_slash( $new ) );
    62         $this->assertEquals( array( 'a' => $new ), wp_slash( array( 'a' => $old ) ) ); // Keyed array.
    63         $this->assertEquals( array( $new ), wp_slash( array( $old ) ) ); // Non-keyed.
     60        $this->assertSame( $new, wp_slash( $old ) );
     61        $this->assertSame( "I can\\\\\'t see, isn\\\\\'t that it?", wp_slash( $new ) );
     62        $this->assertSame( array( 'a' => $new ), wp_slash( array( 'a' => $old ) ) ); // Keyed array.
     63        $this->assertSame( array( $new ), wp_slash( array( $old ) ) ); // Non-keyed.
    6464    }
    6565
     
    6969    function test_preserves_original_datatype() {
    7070
    71         $this->assertEquals( true, wp_slash( true ) );
    72         $this->assertEquals( false, wp_slash( false ) );
    73         $this->assertEquals( 4, wp_slash( 4 ) );
    74         $this->assertEquals( 'foo', wp_slash( 'foo' ) );
     71        $this->assertTrue( wp_slash( true ) );
     72        $this->assertFalse( wp_slash( false ) );
     73        $this->assertSame( 4, wp_slash( 4 ) );
     74        $this->assertSame( 'foo', wp_slash( 'foo' ) );
    7575        $arr      = array(
    7676            'a' => true,
     
    8080        );
    8181        $arr['e'] = $arr; // Add a sub-array.
    82         $this->assertEquals( $arr, wp_slash( $arr ) ); // Keyed array.
    83         $this->assertEquals( array_values( $arr ), wp_slash( array_values( $arr ) ) ); // Non-keyed.
     82        $this->assertSame( $arr, wp_slash( $arr ) ); // Keyed array.
     83        $this->assertSame( array_values( $arr ), wp_slash( array_values( $arr ) ) ); // Non-keyed.
    8484
    8585        $obj = new stdClass;
     
    8787            $obj->$k = $v;
    8888        }
    89         $this->assertEquals( $obj, wp_slash( $obj ) );
     89        $this->assertSame( $obj, wp_slash( $obj ) );
    9090    }
    9191
     
    9696        $old = 'single\\slash double\\\\slash triple\\\\\\slash';
    9797        $new = 'single\\\\slash double\\\\\\\\slash triple\\\\\\\\\\\\slash';
    98         $this->assertEquals( $new, wp_slash( $old ) );
    99         $this->assertEquals( array( 'a' => $new ), wp_slash( array( 'a' => $old ) ) ); // Keyed array.
    100         $this->assertEquals( array( $new ), wp_slash( array( $old ) ) ); // Non-keyed.
     98        $this->assertSame( $new, wp_slash( $old ) );
     99        $this->assertSame( array( 'a' => $new ), wp_slash( array( 'a' => $old ) ) ); // Keyed array.
     100        $this->assertSame( array( $new ), wp_slash( array( $old ) ) ); // Non-keyed.
    101101    }
    102102
Note: See TracChangeset for help on using the changeset viewer.