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

    r47200 r48937  
    5555        $this->assertEquals( '', $users->get( 'fields' ) );
    5656        if ( isset( $users->query_vars['fields'] ) ) {
    57             $this->assertEquals( '', $users->query_vars['fields'] );
     57            $this->assertSame( '', $users->query_vars['fields'] );
    5858        }
    5959
    6060        $users->set( 'fields', 'all' );
    6161
    62         $this->assertEquals( 'all', $users->get( 'fields' ) );
    63         $this->assertEquals( 'all', $users->query_vars['fields'] );
     62        $this->assertSame( 'all', $users->get( 'fields' ) );
     63        $this->assertSame( 'all', $users->query_vars['fields'] );
    6464
    6565        $users->set( 'fields', '' );
    66         $this->assertEquals( '', $users->get( 'fields' ) );
    67         $this->assertEquals( '', $users->query_vars['fields'] );
     66        $this->assertSame( '', $users->get( 'fields' ) );
     67        $this->assertSame( '', $users->query_vars['fields'] );
    6868
    6969        $this->assertNull( $users->get( 'does-not-exist' ) );
     
    7979        $ids = $q->get_results();
    8080
    81         $this->assertEquals( array( self::$author_ids[0] ), $ids );
     81        $this->assertEqualSets( array( self::$author_ids[0] ), $ids );
    8282    }
    8383
     
    138138
    139139        // +1 for the default user created during installation.
    140         $this->assertEquals( 13, count( $users ) );
     140        $this->assertSame( 13, count( $users ) );
    141141        foreach ( $users as $user ) {
    142142            $this->assertInstanceOf( 'WP_User', $user );
     
    150150        );
    151151        $users = $users->get_results();
    152         $this->assertEquals( 13, count( $users ) );
     152        $this->assertSame( 13, count( $users ) );
    153153        foreach ( $users as $user ) {
    154154            $this->assertInstanceOf( 'WP_User', $user );
     
    503503        $users = new WP_User_Query( array( 'blog_id' => get_current_blog_id() ) );
    504504        $users = $users->get_results();
    505         $this->assertEquals( 13, count( $users ) );
     505        $this->assertSame( 13, count( $users ) );
    506506
    507507        $users = new WP_User_Query(
     
    512512        );
    513513        $users = $users->get_results();
    514         $this->assertEquals( 10, count( $users ) );
     514        $this->assertSame( 10, count( $users ) );
    515515
    516516        $users = new WP_User_Query(
     
    521521        );
    522522        $users = $users->get_results();
    523         $this->assertEquals( 2, count( $users ) );
     523        $this->assertSame( 2, count( $users ) );
    524524
    525525        $users = new WP_User_Query(
     
    530530        );
    531531        $users = $users->get_results();
    532         $this->assertEquals( 13, count( $users ) );
     532        $this->assertSame( 13, count( $users ) );
    533533    }
    534534
     
    558558        $query->prepare_query( array( 'number' => 8 ) );
    559559        $this->assertNotEmpty( $query->query_limit );
    560         $this->assertEquals( 'LIMIT 0, 8', $query->query_limit );
     560        $this->assertSame( 'LIMIT 0, 8', $query->query_limit );
    561561
    562562        // All values get reset.
     
    567567
    568568        $query->prepare_query();
    569         $this->assertEquals( $_query_vars, $query->query_vars );
     569        $this->assertSame( $_query_vars, $query->query_vars );
    570570
    571571        $query->prepare_query( array( 'number' => -1 ) );
     
    11431143
    11441144        $this->assertContains( "AND user_nicename NOT IN ( 'peter','paul','mary' )", $q->query_where );
    1145         $this->assertEquals( $expected_count, $found_count );
     1145        $this->assertSame( $expected_count, $found_count );
    11461146    }
    11471147
     
    12441244
    12451245        $this->assertContains( "AND user_login NOT IN ( '$user_login1','$user_login2','$user_login3' )", $q->query_where );
    1246         $this->assertEquals( $expected_count, $found_count );
     1246        $this->assertSame( $expected_count, $found_count );
    12471247    }
    12481248
     
    13151315        $users          = $wp_user_search->get_results();
    13161316
    1317         $this->assertEquals( 2, count( $users ) );
     1317        $this->assertSame( 2, count( $users ) );
    13181318    }
    13191319
     
    13241324        $wp_user_search = new WP_User_Query( array( 'role__in' => array( 'subscriber', 'editor' ) ) );
    13251325        $users          = $wp_user_search->get_results();
    1326         $this->assertEquals( 5, count( $users ) );
     1326        $this->assertSame( 5, count( $users ) );
    13271327    }
    13281328
     
    13371337        );
    13381338
    1339         $this->assertEquals( 2, count( $users ) );
     1339        $this->assertSame( 2, count( $users ) );
    13401340    }
    13411341
     
    13731373        );
    13741374
    1375         $this->assertEquals( 2, count( $users ) );
     1375        $this->assertSame( 2, count( $users ) );
    13761376    }
    13771377
     
    13931393        $users = $users->get_results();
    13941394
    1395         $this->assertEquals( 2, count( $users ) );
     1395        $this->assertSame( 2, count( $users ) );
    13961396
    13971397        foreach ( $users as $user ) {
     
    14081408
    14091409        // +1 for the default user created during installation.
    1410         $this->assertEquals( 8, count( $users ) );
     1410        $this->assertSame( 8, count( $users ) );
    14111411        foreach ( $users as $user ) {
    14121412            $this->assertInstanceOf( 'WP_User', $user );
     
    14371437        );
    14381438
    1439         $this->assertEquals( 2, count( $users ) );
     1439        $this->assertSame( 2, count( $users ) );
    14401440    }
    14411441
     
    14831483
    14841484        // Check results.
    1485         $this->assertEquals( 1, count( $users ) );
     1485        $this->assertSame( 1, count( $users ) );
    14861486        $this->assertSame( self::$editor_ids[0], (int) $users[0]->ID );
    14871487    }
     
    14981498
    14991499        // +1 for the default user created during installation.
    1500         $this->assertEquals( 11, count( $users ) );
     1500        $this->assertSame( 11, count( $users ) );
    15011501
    15021502        $users = get_users(
     
    15071507
    15081508        // +1 for the default user created during installation.
    1509         $this->assertEquals( 10, count( $users ) );
     1509        $this->assertSame( 10, count( $users ) );
    15101510    }
    15111511
     
    15251525        );
    15261526
    1527         $this->assertEquals( 5, count( $users ) );
     1527        $this->assertSame( 5, count( $users ) );
    15281528
    15291529        $users = get_users(
     
    15341534        );
    15351535
    1536         $this->assertEquals( 3, count( $users ) );
     1536        $this->assertSame( 3, count( $users ) );
    15371537    }
    15381538
     
    15511551        );
    15521552
    1553         $this->assertEquals( 1, count( $users ) );
     1553        $this->assertSame( 1, count( $users ) );
    15541554    }
    15551555
     
    15691569
    15701570        // +1 for the default user created during installation.
    1571         $this->assertEquals( 12, count( $users ) );
     1571        $this->assertSame( 12, count( $users ) );
    15721572
    15731573        $users = get_users(
     
    15781578
    15791579        // +1 for the default user created during installation.
    1580         $this->assertEquals( 10, count( $users ) );
     1580        $this->assertSame( 10, count( $users ) );
    15811581    }
    15821582
     
    16911691
    16921692        // Must not include user that has the same string in other fields.
    1693         $this->assertEquals( array(), $ids );
     1693        $this->assertSame( array(), $ids );
    16941694    }
    16951695
     
    17181718
    17191719        // Make sure manually setting total_users doesn't get overwritten.
    1720         $this->assertEquals( 1, $q->total_users );
     1720        $this->assertSame( 1, $q->total_users );
    17211721    }
    17221722
Note: See TracChangeset for help on using the changeset viewer.