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

    r47122 r48937  
    5353
    5454            // User should be a member of the created sites and the network's initial site.
    55             $this->assertEquals( $blog_ids, $blog_ids_of_user );
     55            $this->assertSame( $blog_ids, $blog_ids_of_user );
    5656
    5757            $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[0] ) );
     
    6868            // The user should still be a member of all remaining sites.
    6969            $blog_ids_of_user = array_keys( $blogs_of_user );
    70             $this->assertEquals( $blog_ids, $blog_ids_of_user );
     70            $this->assertSame( $blog_ids, $blog_ids_of_user );
    7171
    7272            // Each site retrieved should match the expected structure.
    7373            foreach ( $blogs_of_user as $blog_id => $blog ) {
    74                 $this->assertEquals( $blog_id, $blog->userblog_id );
     74                $this->assertSame( $blog_id, $blog->userblog_id );
    7575                $this->assertTrue( isset( $blog->userblog_id ) );
    7676                $this->assertTrue( isset( $blog->blogname ) );
     
    9292            $blogs_of_user    = get_blogs_of_user( $user1_id, true );
    9393            $blog_ids_of_user = array_keys( $blogs_of_user );
    94             $this->assertEquals( $blog_ids, $blog_ids_of_user );
     94            $this->assertSame( $blog_ids, $blog_ids_of_user );
    9595
    9696            // Check if sites are flagged as expected.
     
    106106            // Passing false (the default) as the second parameter should retrieve only good sites.
    107107            $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id, false ) );
    108             $this->assertEquals( $blog_ids, $blog_ids_of_user );
     108            $this->assertSame( $blog_ids, $blog_ids_of_user );
    109109        }
    110110
     
    370370            $u_obj = self::factory()->user->create_and_get();
    371371            $this->assertFalse( wpmu_delete_user( $u_obj ) );
    372             $this->assertEquals( $u_obj->ID, username_exists( $u_obj->user_login ) );
     372            $this->assertSame( $u_obj->ID, username_exists( $u_obj->user_login ) );
    373373        }
    374374
Note: See TracChangeset for help on using the changeset viewer.