WordPress.org

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/option/siteOption.php

    r47122 r48937  
    2525        $value = __FUNCTION__;
    2626        add_site_option( $key, $value );
    27         $this->assertEquals( $value, get_site_option( $key ) );
     27        $this->assertSame( $value, get_site_option( $key ) );
    2828    }
    2929
     
    3434        add_site_option( $key, $value );
    3535        update_site_option( $key, $new_value );
    36         $this->assertEquals( $new_value, get_site_option( $key ) );
     36        $this->assertSame( $new_value, get_site_option( $key ) );
    3737    }
    3838
     
    4141        $site_option = get_site_option( 'doesnotexist' );
    4242        remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    43         $this->assertEquals( 'foo', $site_option );
     43        $this->assertSame( 'foo', $site_option );
    4444    }
    4545
     
    4848        $site_option = get_site_option( 'doesnotexist', 'bar' );
    4949        remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) );
    50         $this->assertEquals( 'foo', $site_option );
     50        $this->assertSame( 'foo', $site_option );
    5151    }
    5252
    5353    function test_get_site_option_does_not_exist_returns_provided_default() {
    54         $this->assertEquals( 'bar', get_site_option( 'doesnotexist', 'bar' ) );
     54        $this->assertSame( 'bar', get_site_option( 'doesnotexist', 'bar' ) );
    5555    }
    5656
     
    5959        $value = __FUNCTION__;
    6060        add_site_option( $key, $value );
    61         $this->assertEquals( $value, get_site_option( $key, 'foo' ) );
     61        $this->assertSame( $value, get_site_option( $key, 'foo' ) );
    6262    }
    6363
     
    6969        $site_option = get_site_option( $key );
    7070        remove_filter( 'default_site_option_' . $key, array( $this, '__return_foo' ) );
    71         $this->assertEquals( $value, $site_option );
     71        $this->assertSame( $value, $site_option );
    7272    }
    7373
     
    122122        );
    123123        add_site_option( $key, $value );
    124         $this->assertEquals( $value, get_site_option( $key ) );
     124        $this->assertSame( $value, get_site_option( $key ) );
    125125    }
    126126
     
    158158        $default = 'a default';
    159159
    160         $this->assertEquals( get_site_option( $option, $default ), $default );
     160        $this->assertSame( get_site_option( $option, $default ), $default );
    161161        $this->assertFalse( get_site_option( $option ) );
    162162    }
Note: See TracChangeset for help on using the changeset viewer.