Make WordPress Core


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

    r47122 r48937  
    3838    function test_auth_cookie_valid() {
    3939        $cookie = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'auth' );
    40         $this->assertEquals( self::$user_id, wp_validate_auth_cookie( $cookie, 'auth' ) );
     40        $this->assertSame( self::$user_id, wp_validate_auth_cookie( $cookie, 'auth' ) );
    4141    }
    4242
     
    4646
    4747        $cookie = wp_generate_auth_cookie( self::$user_id, time() - 7200, 'auth' );
    48         $this->assertEquals( false, wp_validate_auth_cookie( $cookie, 'auth' ), 'expired cookie' );
     48        $this->assertFalse( wp_validate_auth_cookie( $cookie, 'auth' ), 'expired cookie' );
    4949
    5050        $cookie = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'auth' );
    51         $this->assertEquals( false, wp_validate_auth_cookie( $cookie, 'logged_in' ), 'wrong auth scheme' );
     51        $this->assertFalse( wp_validate_auth_cookie( $cookie, 'logged_in' ), 'wrong auth scheme' );
    5252
    5353        $cookie          = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'auth' );
    5454        list($a, $b, $c) = explode( '|', $cookie );
    5555        $cookie          = $a . '|' . ( $b + 1 ) . '|' . $c;
    56         $this->assertEquals( false, wp_validate_auth_cookie( self::$user_id, 'auth' ), 'altered cookie' );
     56        $this->assertFalse( wp_validate_auth_cookie( self::$user_id, 'auth' ), 'altered cookie' );
    5757    }
    5858
     
    6060        // Arbitrary scheme name.
    6161        $cookie = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'foo' );
    62         $this->assertEquals( self::$user_id, wp_validate_auth_cookie( $cookie, 'foo' ) );
     62        $this->assertSame( self::$user_id, wp_validate_auth_cookie( $cookie, 'foo' ) );
    6363
    6464        // Wrong scheme name - should fail.
    6565        $cookie = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'foo' );
    66         $this->assertEquals( false, wp_validate_auth_cookie( $cookie, 'bar' ) );
     66        $this->assertFalse( wp_validate_auth_cookie( $cookie, 'bar' ) );
    6767    }
    6868
     
    8383
    8484            $this->assertInstanceOf( 'WP_User', $authed_user );
    85             $this->assertEquals( $this->user->ID, $authed_user->ID );
     85            $this->assertSame( $this->user->ID, $authed_user->ID );
    8686        }
    8787    }
     
    137137        wp_verify_nonce( $nonce, 'nonce_test_action' );
    138138
    139         $this->assertEquals( ( $count + 1 ), did_action( $this->nonce_failure_hook ) );
     139        $this->assertSame( ( $count + 1 ), did_action( $this->nonce_failure_hook ) );
    140140    }
    141141
     
    149149        wp_verify_nonce( $nonce, 'nonce_test_action' );
    150150
    151         $this->assertEquals( $count, did_action( $this->nonce_failure_hook ) );
     151        $this->assertSame( $count, did_action( $this->nonce_failure_hook ) );
    152152    }
    153153
     
    202202        $user = wp_authenticate( $this->user->user_login, $limit );
    203203        $this->assertInstanceOf( 'WP_User', $user );
    204         $this->assertEquals( self::$user_id, $user->ID );
     204        $this->assertSame( self::$user_id, $user->ID );
    205205
    206206        // One char too many.
     
    212212        $user = get_user_by( 'id', self::$user_id );
    213213        // Password broken by setting it to be too long.
    214         $this->assertEquals( '*', $user->data->user_pass );
     214        $this->assertSame( '*', $user->data->user_pass );
    215215
    216216        $user = wp_authenticate( $this->user->user_login, '*' );
Note: See TracChangeset for help on using the changeset viewer.