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/wpDeleteUser.php

    r47122 r48937  
    1313    function test_get_blogs_of_user() {
    1414        // Logged out users don't have blogs.
    15         $this->assertEquals( array(), get_blogs_of_user( 0 ) );
     15        $this->assertSame( array(), get_blogs_of_user( 0 ) );
    1616
    1717        $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    1818        $blogs   = get_blogs_of_user( $user_id );
    19         $this->assertEquals( array( 1 ), array_keys( $blogs ) );
     19        $this->assertSame( array( 1 ), array_keys( $blogs ) );
    2020
    2121        // Non-existent users don't have blogs.
     
    2424        $user = new WP_User( $user_id );
    2525        $this->assertFalse( $user->exists(), 'WP_User->exists' );
    26         $this->assertEquals( array(), get_blogs_of_user( $user_id ) );
     26        $this->assertSame( array(), get_blogs_of_user( $user_id ) );
    2727    }
    2828
     
    7272
    7373        $post = get_post( $post_id );
    74         $this->assertEquals( $post_id, $post->ID );
     74        $this->assertSame( $post_id, $post->ID );
    7575
    7676        $post = array(
     
    8888
    8989        $post = get_post( $nav_id );
    90         $this->assertEquals( $nav_id, $post->ID );
     90        $this->assertSame( $nav_id, $post->ID );
    9191
    9292        wp_delete_user( $user_id );
     
    9999
    100100        $this->assertNotNull( get_post( $post_id ) );
    101         $this->assertEquals( 'trash', get_post( $post_id )->post_status );
     101        $this->assertSame( 'trash', get_post( $post_id )->post_status );
    102102        // 'nav_menu_item' is `delete_with_user = false` so the nav post should remain published.
    103103        $this->assertNotNull( get_post( $nav_id ) );
    104         $this->assertEquals( 'publish', get_post( $nav_id )->post_status );
     104        $this->assertSame( 'publish', get_post( $nav_id )->post_status );
    105105        wp_delete_post( $nav_id, true );
    106106        $this->assertNull( get_post( $nav_id ) );
     
    150150        $u_obj = self::factory()->user->create_and_get();
    151151        $this->assertFalse( wp_delete_user( $u_obj ) );
    152         $this->assertEquals( $u_obj->ID, username_exists( $u_obj->user_login ) );
     152        $this->assertSame( $u_obj->ID, username_exists( $u_obj->user_login ) );
    153153    }
    154154}
Note: See TracChangeset for help on using the changeset viewer.