WordPress.org

Make WordPress Core


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

    r48464 r48937  
    4040
    4141        foreach ( $actual as $header => $value ) {
    42             $this->assertEquals( $expected[ $header ], $value, $header );
     42            $this->assertSame( $expected[ $header ], $value, $header );
    4343        }
    4444    }
     
    6262
    6363        foreach ( $actual as $header => $value ) {
    64             $this->assertEquals( $expected[ $header ], $value, $header );
     64            $this->assertSame( $expected[ $header ], $value, $header );
    6565        }
    6666    }
     
    119119
    120120        // Make sure the bad characters were all stripped out.
    121         $this->assertEquals( $name . '.txt', $filename );
     121        $this->assertSame( $name . '.txt', $filename );
    122122
    123123        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
     
    132132
    133133        // The slash should be removed, i.e. "foofoo.txt".
    134         $this->assertEquals( $name . $name . '.txt', $filename );
     134        $this->assertSame( $name . $name . '.txt', $filename );
    135135
    136136        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
     
    144144
    145145        // "foo.php.txt" becomes "foo.php_.txt".
    146         $this->assertEquals( $name . '.php_.txt', $filename );
     146        $this->assertSame( $name . '.php_.txt', $filename );
    147147
    148148        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
     
    155155        $filename = wp_unique_filename( $this->dir, $name );
    156156
    157         $this->assertEquals( $name, $filename );
     157        $this->assertSame( $name, $filename );
    158158
    159159        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
     
    232232
    233233        $this->assertWPError( $verify );
    234         $this->assertEquals( 'signature_verification_failed', $verify->get_error_code() );
     234        $this->assertSame( 'signature_verification_failed', $verify->get_error_code() );
    235235    }
    236236
Note: See TracChangeset for help on using the changeset viewer.