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

    r47122 r48937  
    1919        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'username', 'password', 'category', 1 ) );
    2020        $this->assertIXRError( $result );
    21         $this->assertEquals( 403, $result->code );
     21        $this->assertSame( 403, $result->code );
    2222    }
    2323
     
    2727        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', '', 0 ) );
    2828        $this->assertIXRError( $result );
    29         $this->assertEquals( 403, $result->code );
    30         $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
     29        $this->assertSame( 403, $result->code );
     30        $this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
    3131    }
    3232
     
    3636        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'not_existing', 0 ) );
    3737        $this->assertIXRError( $result );
    38         $this->assertEquals( 403, $result->code );
    39         $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
     38        $this->assertSame( 403, $result->code );
     39        $this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
    4040    }
    4141
     
    4545        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', self::$term_id ) );
    4646        $this->assertIXRError( $result );
    47         $this->assertEquals( 401, $result->code );
    48         $this->assertEquals( __( 'Sorry, you are not allowed to assign this term.' ), $result->message );
     47        $this->assertSame( 401, $result->code );
     48        $this->assertSame( __( 'Sorry, you are not allowed to assign this term.' ), $result->message );
    4949    }
    5050
     
    5555        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', '' ) );
    5656        $this->assertIXRError( $result );
    57         $this->assertEquals( 500, $result->code );
    58         $this->assertEquals( __( 'Empty Term.' ), $result->message );
     57        $this->assertSame( 500, $result->code );
     58        $this->assertSame( __( 'Empty Term.' ), $result->message );
    5959    }
    6060
     
    6464        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', 9999 ) );
    6565        $this->assertIXRError( $result );
    66         $this->assertEquals( 404, $result->code );
    67         $this->assertEquals( __( 'Invalid term ID.' ), $result->message );
     66        $this->assertSame( 404, $result->code );
     67        $this->assertSame( __( 'Invalid term ID.' ), $result->message );
    6868    }
    6969
     
    9393
    9494        // Check data.
    95         $this->assertEquals( 0, $result['count'] );
    96         $this->assertEquals( $term['name'], $result['name'] );
    97         $this->assertEquals( $term['slug'], $result['slug'] );
    98         $this->assertEquals( 'category', $result['taxonomy'] );
    99         $this->assertEquals( $term['description'], $result['description'] );
     95        $this->assertSame( 0, $result['count'] );
     96        $this->assertSame( $term['name'], $result['name'] );
     97        $this->assertSame( $term['slug'], $result['slug'] );
     98        $this->assertSame( 'category', $result['taxonomy'] );
     99        $this->assertSame( $term['description'], $result['description'] );
    100100    }
    101101
     
    124124        $this->assertInternalType( 'array', $result['custom_fields'] );
    125125        $term_meta = get_term_meta( self::$term_id, '', true );
    126         $this->assertEquals( $term_meta['foo'][0], $result['custom_fields'][0]['value'] );
     126        $this->assertSame( $term_meta['foo'][0], $result['custom_fields'][0]['value'] );
    127127    }
    128128}
Note: See TracChangeset for help on using the changeset viewer.