Make WordPress Core


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

    r46586 r48937  
    1212
    1313                $args = $registered['test_option'];
    14                 $this->assertEquals( 'test_group', $args['group'] );
     14                $this->assertSame( 'test_group', $args['group'] );
    1515
    1616                // Check defaults.
    17                 $this->assertEquals( 'string', $args['type'] );
    18                 $this->assertEquals( false, $args['show_in_rest'] );
    19                 $this->assertEquals( '', $args['description'] );
     17                $this->assertSame( 'string', $args['type'] );
     18                $this->assertFalse( $args['show_in_rest'] );
     19                $this->assertSame( '', $args['description'] );
    2020        }
    2121
    … …  
    2424
    2525                $filtered = apply_filters( 'sanitize_option_test_option', 'smart', 'test_option', 'smart' );
    26                 $this->assertEquals( 'S-M-R-T', $filtered );
     26                $this->assertSame( 'S-M-R-T', $filtered );
    2727        }
    2828
    … …  
    3737
    3838                $filtered = apply_filters( 'sanitize_option_test_option', 'smart', 'test_option', 'smart' );
    39                 $this->assertEquals( 'S-M-R-T', $filtered );
     39                $this->assertSame( 'S-M-R-T', $filtered );
    4040        }
    4141
    … …  
    5656                );
    5757
    58                 $this->assertEquals( 'Got that Viper with them rally stripes', get_option( 'test_default' ) );
     58                $this->assertSame( 'Got that Viper with them rally stripes', get_option( 'test_default' ) );
    5959        }
    6060
    … …  
    7373                // This set of tests/references (and a previous version) are in support of Viper007Bond.
    7474                // His Viper doesn't have rally stripes, but for the sake of the Big Tymers, we'll go with it.
    75                 $this->assertEquals( 'We the #1 Stunnas', get_option( 'test_default', 'We the #1 Stunnas' ) );
     75                $this->assertSame( 'We the #1 Stunnas', get_option( 'test_default', 'We the #1 Stunnas' ) );
    7676        }
    7777
    … …  
    8989                wp_cache_delete( 'notoptions', 'options' );
    9090                $this->assertTrue( add_option( 'test_default', 'hello' ) );
    91                 $this->assertEquals( 'hello', get_option( 'test_default' ) );
     91                $this->assertSame( 'hello', get_option( 'test_default' ) );
    9292        }
    9393
Note: See TracChangeset for help on using the changeset viewer.