WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/09/2020 03:43:14 PM (12 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in some newly introduced 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.

Follow-up to [48937], [48939], [48940], [48944].

See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/auth.php

    r49109 r49547  
    452452        $_SERVER['PHP_AUTH_PW']   = 'http_auth_pass';
    453453
    454         $this->assertEquals(
    455             0,
     454        $this->assertSame(
     455            null,
    456456            wp_validate_application_password( null ),
    457457            'Regular user account password should not be allowed for API authentication'
     
    461461        $_SERVER['PHP_AUTH_PW'] = $user_app_password;
    462462
    463         $this->assertEquals(
     463        $this->assertSame(
    464464            $user_id,
    465465            wp_validate_application_password( null ),
     
    492492        $error = wp_authenticate_application_password( null, 'idonotexist', 'password' );
    493493        $this->assertWPError( $error );
    494         $this->assertEquals( 'invalid_username', $error->get_error_code() );
     494        $this->assertSame( 'invalid_username', $error->get_error_code() );
    495495    }
    496496
     
    503503        $error = wp_authenticate_application_password( null, 'idonotexist@example.org', 'password' );
    504504        $this->assertWPError( $error );
    505         $this->assertEquals( 'invalid_email', $error->get_error_code() );
     505        $this->assertSame( 'invalid_email', $error->get_error_code() );
    506506    }
    507507
     
    515515        $error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
    516516        $this->assertWPError( $error );
    517         $this->assertEquals( 'application_passwords_disabled', $error->get_error_code() );
     517        $this->assertSame( 'application_passwords_disabled', $error->get_error_code() );
    518518    }
    519519
     
    528528        $error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
    529529        $this->assertWPError( $error );
    530         $this->assertEquals( 'application_passwords_disabled', $error->get_error_code() );
     530        $this->assertSame( 'application_passwords_disabled', $error->get_error_code() );
    531531    }
    532532
     
    540540        $error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
    541541        $this->assertWPError( $error );
    542         $this->assertEquals( 'incorrect_password', $error->get_error_code() );
     542        $this->assertSame( 'incorrect_password', $error->get_error_code() );
    543543    }
    544544
     
    561561        $error = wp_authenticate_application_password( null, self::$_user->user_login, $password );
    562562        $this->assertWPError( $error );
    563         $this->assertEquals( 'my_code', $error->get_error_code() );
     563        $this->assertSame( 'my_code', $error->get_error_code() );
    564564    }
    565565
     
    575575        $user = wp_authenticate_application_password( null, self::$_user->user_login, $password );
    576576        $this->assertInstanceOf( WP_User::class, $user );
    577         $this->assertEquals( self::$user_id, $user->ID );
     577        $this->assertSame( self::$user_id, $user->ID );
    578578    }
    579579
     
    589589        $user = wp_authenticate_application_password( null, self::$_user->user_email, $password );
    590590        $this->assertInstanceOf( WP_User::class, $user );
    591         $this->assertEquals( self::$user_id, $user->ID );
     591        $this->assertSame( self::$user_id, $user->ID );
    592592    }
    593593
     
    603603        $user = wp_authenticate_application_password( null, self::$_user->user_email, WP_Application_Passwords::chunk_password( $password ) );
    604604        $this->assertInstanceOf( WP_User::class, $user );
    605         $this->assertEquals( self::$user_id, $user->ID );
     605        $this->assertSame( self::$user_id, $user->ID );
    606606    }
    607607}
Note: See TracChangeset for help on using the changeset viewer.