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

    r47122 r48937  
    99        $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'username', 'password', 'category' ) );
    1010        $this->assertIXRError( $result );
    11         $this->assertEquals( 403, $result->code );
     11        $this->assertSame( 403, $result->code );
    1212    }
    1313
     
    1717        $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', '' ) );
    1818        $this->assertIXRError( $result );
    19         $this->assertEquals( 403, $result->code );
    20         $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
     19        $this->assertSame( 403, $result->code );
     20        $this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
    2121    }
    2222
     
    2626        $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'not_existing' ) );
    2727        $this->assertIXRError( $result );
    28         $this->assertEquals( 403, $result->code );
    29         $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
     28        $this->assertSame( 403, $result->code );
     29        $this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
    3030    }
    3131
     
    3535        $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'subscriber', 'subscriber', 'category' ) );
    3636        $this->assertIXRError( $result );
    37         $this->assertEquals( 401, $result->code );
    38         $this->assertEquals( __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ), $result->message );
     37        $this->assertSame( 401, $result->code );
     38        $this->assertSame( __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ), $result->message );
    3939    }
    4040
     
    7878        $this->assertNotIXRError( $results );
    7979
    80         $this->assertEquals( $num_terms, count( $results ) );
     80        $this->assertSame( $num_terms, count( $results ) );
    8181        foreach ( $results as $term ) {
    82             $this->assertEquals( $tax_name, $term['taxonomy'] );
     82            $this->assertSame( $tax_name, $term['taxonomy'] );
    8383        }
    8484
     
    8787        $results2 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) );
    8888        $this->assertNotIXRError( $results );
    89         $this->assertEquals( 5, count( $results2 ) );
    90         $this->assertEquals( $results[1]['term_id'], $results2[1]['term_id'] ); // Check one of the terms.
     89        $this->assertSame( 5, count( $results2 ) );
     90        $this->assertSame( $results[1]['term_id'], $results2[1]['term_id'] ); // Check one of the terms.
    9191
    9292        $filter['offset'] = 10;
    9393        $results3         = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) );
    9494        $this->assertNotIXRError( $results3 );
    95         $this->assertEquals( $num_terms - 10, count( $results3 ) );
    96         $this->assertEquals( $results[11]['term_id'], $results3[1]['term_id'] );
     95        $this->assertSame( $num_terms - 10, count( $results3 ) );
     96        $this->assertSame( $results[11]['term_id'], $results3[1]['term_id'] );
    9797
    9898        // Test hide_empty (since none have been attached to posts yet, all should be hidden.
     
    100100        $results4 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) );
    101101        $this->assertNotIXRError( $results4 );
    102         $this->assertEquals( 0, count( $results4 ) );
     102        $this->assertSame( 0, count( $results4 ) );
    103103
    104104        unset( $GLOBALS['wp_taxonomies'][ $tax_name ] );
     
    141141        $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) );
    142142        $this->assertNotIXRError( $results );
    143         $this->assertEquals( 1, count( $results ) );
    144         $this->assertEquals( $name, $results[0]['name'] );
     143        $this->assertSame( 1, count( $results ) );
     144        $this->assertSame( $name, $results[0]['name'] );
    145145        $this->assertEquals( $name_id, $results[0]['term_id'] );
    146146
     
    149149        $results2 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) );
    150150        $this->assertNotIXRError( $results2 );
    151         $this->assertEquals( 1, count( $results2 ) );
    152         $this->assertEquals( $name, $results2[0]['name'] );
     151        $this->assertSame( 1, count( $results2 ) );
     152        $this->assertSame( $name, $results2[0]['name'] );
    153153        $this->assertEquals( $name_id, $results2[0]['term_id'] );
    154154    }
Note: See TracChangeset for help on using the changeset viewer.