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

    r46586 r48937  
    3030        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'username', 'password', 'category', 1 ) );
    3131        $this->assertIXRError( $result );
    32         $this->assertEquals( 403, $result->code );
     32        $this->assertSame( 403, $result->code );
    3333    }
    3434
     
    3838        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', '', array( 'taxonomy' => '' ) ) );
    3939        $this->assertIXRError( $result );
    40         $this->assertEquals( 403, $result->code );
    41         $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
     40        $this->assertSame( 403, $result->code );
     41        $this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
    4242    }
    4343
     
    4747        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', self::$parent_term, array( 'taxonomy' => 'not_existing' ) ) );
    4848        $this->assertIXRError( $result );
    49         $this->assertEquals( 403, $result->code );
    50         $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
     49        $this->assertSame( 403, $result->code );
     50        $this->assertSame( __( 'Invalid taxonomy.' ), $result->message );
    5151    }
    5252
     
    5656        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', self::$parent_term, array( 'taxonomy' => 'category' ) ) );
    5757        $this->assertIXRError( $result );
    58         $this->assertEquals( 401, $result->code );
    59         $this->assertEquals( __( 'Sorry, you are not allowed to edit this term.' ), $result->message );
     58        $this->assertSame( 401, $result->code );
     59        $this->assertSame( __( 'Sorry, you are not allowed to edit this term.' ), $result->message );
    6060    }
    6161
     
    6565        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', 9999, array( 'taxonomy' => 'category' ) ) );
    6666        $this->assertIXRError( $result );
    67         $this->assertEquals( 404, $result->code );
    68         $this->assertEquals( __( 'Invalid term ID.' ), $result->message );
     67        $this->assertSame( 404, $result->code );
     68        $this->assertSame( __( 'Invalid term ID.' ), $result->message );
    6969    }
    7070
     
    7474        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', '', array( 'taxonomy' => 'category' ) ) );
    7575        $this->assertIXRError( $result );
    76         $this->assertEquals( 500, $result->code );
    77         $this->assertEquals( __( 'Empty Term.' ), $result->message );
     76        $this->assertSame( 500, $result->code );
     77        $this->assertSame( __( 'Empty Term.' ), $result->message );
    7878    }
    7979
     
    9494        );
    9595        $this->assertIXRError( $result );
    96         $this->assertEquals( 403, $result->code );
    97         $this->assertEquals( __( 'The term name cannot be empty.' ), $result->message );
     96        $this->assertSame( 403, $result->code );
     97        $this->assertSame( __( 'The term name cannot be empty.' ), $result->message );
    9898    }
    9999
     
    114114        );
    115115        $this->assertIXRError( $result );
    116         $this->assertEquals( 403, $result->code );
    117         $this->assertEquals( __( 'Cannot set parent term, taxonomy is not hierarchical.' ), $result->message );
     116        $this->assertSame( 403, $result->code );
     117        $this->assertSame( __( 'Cannot set parent term, taxonomy is not hierarchical.' ), $result->message );
    118118    }
    119119
     
    179179        );
    180180        $this->assertIXRError( $result );
    181         $this->assertEquals( 500, $result->code );
     181        $this->assertSame( 500, $result->code );
    182182    }
    183183
     
    199199        );
    200200        $this->assertIXRError( $result );
    201         $this->assertEquals( 403, $result->code );
    202         $this->assertEquals( __( 'Parent term does not exist.' ), $result->message );
     201        $this->assertSame( 403, $result->code );
     202        $this->assertSame( __( 'Parent term does not exist.' ), $result->message );
    203203    }
    204204
     
    220220        );
    221221        $this->assertIXRError( $result );
    222         $this->assertEquals( 500, $result->code );
    223         $this->assertEquals( htmlspecialchars( sprintf( __( 'The slug “%s” is already in use by another term.' ), $parent_term->slug ) ), $result->message );
     222        $this->assertSame( 500, $result->code );
     223        $this->assertSame( htmlspecialchars( sprintf( __( 'The slug “%s” is already in use by another term.' ), $parent_term->slug ) ), $result->message );
    224224    }
    225225
Note: See TracChangeset for help on using the changeset viewer.