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

    r48603 r48937  
    88        # r17990
    99        $file_name = sanitize_file_name( 'test.phtml.txt' );
    10         $this->assertEquals( 'test.phtml_.txt', $file_name );
     10        $this->assertSame( 'test.phtml_.txt', $file_name );
    1111    }
    1212
     
    1818        }
    1919        $string .= 'test';
    20         $this->assertEquals( 'testtest', sanitize_file_name( $string ) );
     20        $this->assertSame( 'testtest', sanitize_file_name( $string ) );
    2121    }
    2222
     
    2727        $in  = 'àáâãäåæçèéêëìíîïñòóôõöøùúûüýÿ';
    2828        $out = 'aaaaaaaeceeeeiiiinoooooouuuuyy';
    29         $this->assertEquals( $out, sanitize_file_name( $in ) );
     29        $this->assertSame( $out, sanitize_file_name( $in ) );
    3030    }
    3131
     
    4444
    4545        foreach ( $urls as $test => $expected ) {
    46             $this->assertEquals( $expected, sanitize_file_name( $test ) );
     46            $this->assertSame( $expected, sanitize_file_name( $test ) );
    4747        }
    4848    }
    4949
    5050    function test_replaces_any_number_of_hyphens_with_one_hyphen() {
    51         $this->assertEquals( 'a-t-t', sanitize_file_name( 'a----t----t' ) );
     51        $this->assertSame( 'a-t-t', sanitize_file_name( 'a----t----t' ) );
    5252    }
    5353
    5454    function test_trims_trailing_hyphens() {
    55         $this->assertEquals( 'a-t-t', sanitize_file_name( 'a----t----t----' ) );
     55        $this->assertSame( 'a-t-t', sanitize_file_name( 'a----t----t----' ) );
    5656    }
    5757
    5858    function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
    59         $this->assertEquals( 'a-t', sanitize_file_name( 'a          t' ) );
    60         $this->assertEquals( 'a-t', sanitize_file_name( "a    \n\n\nt" ) );
     59        $this->assertSame( 'a-t', sanitize_file_name( 'a          t' ) );
     60        $this->assertSame( 'a-t', sanitize_file_name( "a    \n\n\nt" ) );
    6161    }
    6262
     
    6565     */
    6666    function test_replaces_percent_sign() {
    67         $this->assertEquals( 'a22b.jpg', sanitize_file_name( 'a%22b.jpg' ) );
     67        $this->assertSame( 'a22b.jpg', sanitize_file_name( 'a%22b.jpg' ) );
    6868    }
    6969
    7070    function test_replaces_unnamed_file_extensions() {
    7171        // Test filenames with both supported and unsupported extensions.
    72         $this->assertEquals( 'unnamed-file.exe', sanitize_file_name( '_.exe' ) );
    73         $this->assertEquals( 'unnamed-file.jpg', sanitize_file_name( '_.jpg' ) );
     72        $this->assertSame( 'unnamed-file.exe', sanitize_file_name( '_.exe' ) );
     73        $this->assertSame( 'unnamed-file.jpg', sanitize_file_name( '_.jpg' ) );
    7474    }
    7575
    7676    function test_replaces_unnamed_file_extensionless() {
    7777        // Test a filenames that becomes extensionless.
    78         $this->assertEquals( 'no-extension', sanitize_file_name( '_.no-extension' ) );
     78        $this->assertSame( 'no-extension', sanitize_file_name( '_.no-extension' ) );
    7979    }
    8080
     
    8383     */
    8484    function test_replaces_invalid_utf8_characters( $input, $expected ) {
    85         $this->assertEquals( $expected, sanitize_file_name( $input ) );
     85        $this->assertSame( $expected, sanitize_file_name( $input ) );
    8686    }
    8787
Note: See TracChangeset for help on using the changeset viewer.