Make WordPress Core


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

    r47122 r48937  
    1818        $this->assertFalse( get_option( 'doesnotexist' ) );
    1919        $this->assertTrue( add_option( $key, $value ) );
    20         $this->assertEquals( $value, get_option( $key ) );
     20        $this->assertSame( $value, get_option( $key ) );
    2121        $this->assertFalse( add_option( $key, $value ) );    // Already exists.
    2222        $this->assertFalse( update_option( $key, $value ) ); // Value is the same.
    2323        $this->assertTrue( update_option( $key, $value2 ) );
    24         $this->assertEquals( $value2, get_option( $key ) );
     24        $this->assertSame( $value2, get_option( $key ) );
    2525        $this->assertFalse( add_option( $key, $value ) );
    26         $this->assertEquals( $value2, get_option( $key ) );
     26        $this->assertSame( $value2, get_option( $key ) );
    2727        $this->assertTrue( delete_option( $key ) );
    2828        $this->assertFalse( get_option( $key ) );
     
    3030
    3131        $this->assertTrue( update_option( $key2, $value2 ) );
    32         $this->assertEquals( $value2, get_option( $key2 ) );
     32        $this->assertSame( $value2, get_option( $key2 ) );
    3333        $this->assertTrue( delete_option( $key2 ) );
    3434        $this->assertFalse( get_option( $key2 ) );
     
    4242        // Default filter overrides $default arg.
    4343        add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    44         $this->assertEquals( 'foo', get_option( 'doesnotexist', 'bar' ) );
     44        $this->assertSame( 'foo', get_option( 'doesnotexist', 'bar' ) );
    4545
    4646        // Remove the filter and the $default arg is honored.
    4747        remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    48         $this->assertEquals( 'bar', get_option( 'doesnotexist', 'bar' ) );
     48        $this->assertSame( 'bar', get_option( 'doesnotexist', 'bar' ) );
    4949
    5050        // Once the option exists, the $default arg and the default filter are ignored.
    5151        add_option( 'doesnotexist', $value );
    52         $this->assertEquals( $value, get_option( 'doesnotexist', 'foo' ) );
     52        $this->assertSame( $value, get_option( 'doesnotexist', 'foo' ) );
    5353        add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    54         $this->assertEquals( $value, get_option( 'doesnotexist', 'foo' ) );
     54        $this->assertSame( $value, get_option( 'doesnotexist', 'foo' ) );
    5555        remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    5656
     
    8080
    8181        $this->assertTrue( add_option( $key, $value ) );
    82         $this->assertEquals( $value, get_option( $key ) );
     82        $this->assertSame( $value, get_option( $key ) );
    8383
    8484        $value = (object) $value;
     
    139139
    140140        $actual = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $name ) );
    141         $this->assertEquals( $expected, $actual->autoload );
     141        $this->assertSame( $expected, $actual->autoload );
    142142    }
    143143}
Note: See TracChangeset for help on using the changeset viewer.