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/user/author.php

    r47122 r48937  
    4848        $user        = new WP_User( self::$author_id );
    4949
    50         $this->assertEquals( $user->display_name, $author_name );
    51         $this->assertEquals( 'test_author', $author_name );
     50        $this->assertSame( $user->display_name, $author_name );
     51        $this->assertSame( 'test_author', $author_name );
    5252    }
    5353
    5454    function test_get_the_author_meta() {
    55         $this->assertEquals( 'test_author', get_the_author_meta( 'login' ) );
    56         $this->assertEquals( 'test_author', get_the_author_meta( 'user_login' ) );
    57         $this->assertEquals( 'test_author', get_the_author_meta( 'display_name' ) );
     55        $this->assertSame( 'test_author', get_the_author_meta( 'login' ) );
     56        $this->assertSame( 'test_author', get_the_author_meta( 'user_login' ) );
     57        $this->assertSame( 'test_author', get_the_author_meta( 'display_name' ) );
    5858
    59         $this->assertEquals( 'test_author', trim( get_the_author_meta( 'description' ) ) );
    60         $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
     59        $this->assertSame( 'test_author', trim( get_the_author_meta( 'description' ) ) );
     60        $this->assertSame( 'test_author', get_the_author_meta( 'user_description' ) );
    6161        add_user_meta( self::$author_id, 'user_description', 'user description' );
    62         $this->assertEquals( 'user description', get_user_meta( self::$author_id, 'user_description', true ) );
     62        $this->assertSame( 'user description', get_user_meta( self::$author_id, 'user_description', true ) );
    6363        // user_description in meta is ignored. The content of description is returned instead.
    6464        // See #20285.
    65         $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
    66         $this->assertEquals( 'test_author', trim( get_the_author_meta( 'description' ) ) );
     65        $this->assertSame( 'test_author', get_the_author_meta( 'user_description' ) );
     66        $this->assertSame( 'test_author', trim( get_the_author_meta( 'description' ) ) );
    6767        update_user_meta( self::$author_id, 'user_description', '' );
    68         $this->assertEquals( '', get_user_meta( self::$author_id, 'user_description', true ) );
    69         $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
    70         $this->assertEquals( 'test_author', trim( get_the_author_meta( 'description' ) ) );
     68        $this->assertSame( '', get_user_meta( self::$author_id, 'user_description', true ) );
     69        $this->assertSame( 'test_author', get_the_author_meta( 'user_description' ) );
     70        $this->assertSame( 'test_author', trim( get_the_author_meta( 'description' ) ) );
    7171
    72         $this->assertEquals( '', get_the_author_meta( 'does_not_exist' ) );
     72        $this->assertSame( '', get_the_author_meta( 'does_not_exist' ) );
    7373    }
    7474
    7575    function test_get_the_author_meta_no_authordata() {
    7676        unset( $GLOBALS['authordata'] );
    77         $this->assertEquals( '', get_the_author_meta( 'id' ) );
    78         $this->assertEquals( '', get_the_author_meta( 'user_login' ) );
    79         $this->assertEquals( '', get_the_author_meta( 'does_not_exist' ) );
     77        $this->assertSame( '', get_the_author_meta( 'id' ) );
     78        $this->assertSame( '', get_the_author_meta( 'user_login' ) );
     79        $this->assertSame( '', get_the_author_meta( 'does_not_exist' ) );
    8080    }
    8181
    8282    function test_get_the_author_posts() {
    8383        // Test with no global post, result should be 0 because no author is found.
    84         $this->assertEquals( 0, get_the_author_posts() );
     84        $this->assertSame( 0, get_the_author_posts() );
    8585        $GLOBALS['post'] = self::$post_id;
    8686        $this->assertEquals( 1, get_the_author_posts() );
Note: See TracChangeset for help on using the changeset viewer.