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.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-09-02 00:35:36 +00:00
parent ba7c6a2d5f
commit 164b22cf6a
426 changed files with 7959 additions and 7949 deletions

View File

@@ -14,7 +14,7 @@ class Tests_Basic extends WP_UnitTestCase {
$license = file_get_contents( ABSPATH . 'license.txt' );
preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches );
$this_year = gmdate( 'Y' );
$this->assertEquals( $this_year, trim( $matches[1] ), "license.txt's year needs to be updated to $this_year." );
$this->assertSame( $this_year, trim( $matches[1] ), "license.txt's year needs to be updated to $this_year." );
}
function test_security_md() {
@@ -25,7 +25,7 @@ class Tests_Basic extends WP_UnitTestCase {
preg_match( '#\d.\d.x#', $security, $matches );
$current_version = substr( $GLOBALS['wp_version'], 0, 3 );
$latest_stable = sprintf( '%s.x', (float) $current_version - 0.1 );
$this->assertEquals( $latest_stable, trim( $matches[0] ), "SECURITY.md's version needs to be updated to $latest_stable." );
$this->assertSame( $latest_stable, trim( $matches[0] ), "SECURITY.md's version needs to be updated to $latest_stable." );
}
function test_package_json() {
@@ -36,7 +36,7 @@ class Tests_Basic extends WP_UnitTestCase {
if ( 1 === substr_count( $version, '.' ) ) {
$version .= '.0';
}
$this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
$this->assertSame( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
return $package_json;
}
@@ -53,9 +53,9 @@ class Tests_Basic extends WP_UnitTestCase {
// Test some helper utility functions.
function test_strip_ws() {
$this->assertEquals( '', strip_ws( '' ) );
$this->assertEquals( 'foo', strip_ws( 'foo' ) );
$this->assertEquals( '', strip_ws( "\r\n\t \n\r\t" ) );
$this->assertSame( '', strip_ws( '' ) );
$this->assertSame( 'foo', strip_ws( 'foo' ) );
$this->assertSame( '', strip_ws( "\r\n\t \n\r\t" ) );
$in = "asdf\n";
$in .= "asdf asdf\n";
@@ -75,7 +75,7 @@ class Tests_Basic extends WP_UnitTestCase {
$expected .= "foo bar\n";
$expected .= 'foo';
$this->assertEquals( $expected, strip_ws( $in ) );
$this->assertSame( $expected, strip_ws( $in ) );
}
@@ -93,6 +93,6 @@ EOF;
<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
<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]">
EOF;
$this->assertEquals( $expected, mask_input_value( $in ) );
$this->assertSame( $expected, mask_input_value( $in ) );
}
}