Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (3 years 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/getTaxonomy.php

    r46586 r48937  
    99        $result = $this->myxmlrpcserver->wp_getTaxonomy( 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_getTaxonomy( 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_getTaxonomy( 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_getTaxonomy( 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
     
    5252        $this->assertNotIXRError( $result );
    5353        $taxonomy = get_taxonomy( 'category' );
    54         $this->assertEquals( 'category', $result['name'], 'name' );
    55         $this->assertEquals( true, $result['_builtin'], '_builtin' );
    56         $this->assertEquals( $taxonomy->show_ui, $result['show_ui'], 'show_ui' );
    57         $this->assertEquals( $taxonomy->public, $result['public'], 'public' );
    58         $this->assertEquals( $taxonomy->hierarchical, $result['hierarchical'], 'hierarchical' );
    59         $this->assertEquals( (array) $taxonomy->labels, $result['labels'], 'labels' );
    60         $this->assertEquals( (array) $taxonomy->cap, $result['cap'], 'capabilities' );
    61         $this->assertEquals( (array) $taxonomy->object_type, $result['object_type'], 'object_types' );
     54        $this->assertSame( 'category', $result['name'], 'name' );
     55        $this->assertTrue( $result['_builtin'], '_builtin' );
     56        $this->assertSame( $taxonomy->show_ui, $result['show_ui'], 'show_ui' );
     57        $this->assertSame( $taxonomy->public, $result['public'], 'public' );
     58        $this->assertSame( $taxonomy->hierarchical, $result['hierarchical'], 'hierarchical' );
     59        $this->assertSame( (array) $taxonomy->labels, $result['labels'], 'labels' );
     60        $this->assertSame( (array) $taxonomy->cap, $result['cap'], 'capabilities' );
     61        $this->assertSame( (array) $taxonomy->object_type, $result['object_type'], 'object_types' );
    6262    }
    6363}
Note: See TracChangeset for help on using the changeset viewer.