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/xmlrpc/wp/getPosts.php

    r47122 r48937  
    99        $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'username', 'password' ) );
    1010        $this->assertIXRError( $result );
    11         $this->assertEquals( 403, $result->code );
     11        $this->assertSame( 403, $result->code );
    1212    }
    1313
     
    2020        $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'subscriber', 'subscriber' ) );
    2121        $this->assertIXRError( $result );
    22         $this->assertEquals( 401, $result->code );
     22        $this->assertSame( 401, $result->code );
    2323
    2424        $filter = array( 'post_type' => 'page' );
    2525        $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'subscriber', 'subscriber', $filter ) );
    2626        $this->assertIXRError( $result );
    27         $this->assertEquals( 401, $result->code );
     27        $this->assertSame( 401, $result->code );
    2828    }
    2929
     
    7272        $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
    7373        $this->assertNotIXRError( $results );
    74         $this->assertEquals( $num_posts, count( $results ) );
     74        $this->assertSame( $num_posts, count( $results ) );
    7575
    7676        // Page through results.
     
    8484        } while ( count( $presults ) > 0 );
    8585        // Verify that $post_ids matches $posts_found.
    86         $this->assertEquals( 0, count( array_diff( $post_ids, $posts_found ) ) );
     86        $this->assertSame( 0, count( array_diff( $post_ids, $posts_found ) ) );
    8787
    8888        // Add comments to some of the posts.
     
    118118        $results3 = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter3 ) );
    119119        $this->assertNotIXRError( $results3 );
    120         $this->assertEquals( 1, count( $results3 ) );
     120        $this->assertSame( 1, count( $results3 ) );
    121121        $this->assertEquals( $post->ID, $results3[0]['post_id'] );
    122122
     
    160160        $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
    161161        $this->assertNotIXRError( $results );
    162         $this->assertEquals( 0, count( $results ) );
     162        $this->assertSame( 0, count( $results ) );
    163163
    164164        // Search for one of them.
     
    166166        $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
    167167        $this->assertNotIXRError( $results );
    168         $this->assertEquals( 1, count( $results ) );
     168        $this->assertSame( 1, count( $results ) );
    169169    }
    170170
Note: See TracChangeset for help on using the changeset viewer.