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

    r47403 r48937  
    1515        preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches );
    1616        $this_year = gmdate( 'Y' );
    17         $this->assertEquals( $this_year, trim( $matches[1] ), "license.txt's year needs to be updated to $this_year." );
     17        $this->assertSame( $this_year, trim( $matches[1] ), "license.txt's year needs to be updated to $this_year." );
    1818    }
    1919
     
    2626        $current_version = substr( $GLOBALS['wp_version'], 0, 3 );
    2727        $latest_stable   = sprintf( '%s.x', (float) $current_version - 0.1 );
    28         $this->assertEquals( $latest_stable, trim( $matches[0] ), "SECURITY.md's version needs to be updated to $latest_stable." );
     28        $this->assertSame( $latest_stable, trim( $matches[0] ), "SECURITY.md's version needs to be updated to $latest_stable." );
    2929    }
    3030
     
    3737            $version .= '.0';
    3838        }
    39         $this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
     39        $this->assertSame( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
    4040        return $package_json;
    4141    }
     
    5454
    5555    function test_strip_ws() {
    56         $this->assertEquals( '', strip_ws( '' ) );
    57         $this->assertEquals( 'foo', strip_ws( 'foo' ) );
    58         $this->assertEquals( '', strip_ws( "\r\n\t  \n\r\t" ) );
     56        $this->assertSame( '', strip_ws( '' ) );
     57        $this->assertSame( 'foo', strip_ws( 'foo' ) );
     58        $this->assertSame( '', strip_ws( "\r\n\t  \n\r\t" ) );
    5959
    6060        $in  = "asdf\n";
     
    7676        $expected .= 'foo';
    7777
    78         $this->assertEquals( $expected, strip_ws( $in ) );
     78        $this->assertSame( $expected, strip_ws( $in ) );
    7979
    8080    }
     
    9494        <ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="***" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user  <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
    9595EOF;
    96         $this->assertEquals( $expected, mask_input_value( $in ) );
     96        $this->assertSame( $expected, mask_input_value( $in ) );
    9797    }
    9898}
Note: See TracChangeset for help on using the changeset viewer.