Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (6 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/rest-api/rest-post-statuses-controller.php

    r47122 r48937  
    2323                $response = rest_get_server()->dispatch( $request );
    2424                $data     = $response->get_data();
    25                 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     25                $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
    2626                $this->assertEqualSets( array( 'embed', 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    2727                // Single.
     
    2929                $response = rest_get_server()->dispatch( $request );
    3030                $data     = $response->get_data();
    31                 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
     31                $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
    3232                $this->assertEqualSets( array( 'embed', 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    3333        }
     
    3939                $data     = $response->get_data();
    4040                $statuses = get_post_stati( array( 'public' => true ), 'objects' );
    41                 $this->assertEquals( 1, count( $data ) );
    42                 $this->assertEquals( 'publish', $data['publish']['slug'] );
     41                $this->assertSame( 1, count( $data ) );
     42                $this->assertSame( 'publish', $data['publish']['slug'] );
    4343        }
    4444
     
    5151
    5252                $data = $response->get_data();
    53                 $this->assertEquals( 6, count( $data ) );
     53                $this->assertSame( 6, count( $data ) );
    5454                $this->assertEqualSets(
    5555                        array(
     
    107107                $request  = new WP_REST_Request( 'POST', '/wp/v2/statuses' );
    108108                $response = rest_get_server()->dispatch( $request );
    109                 $this->assertEquals( 404, $response->get_status() );
     109                $this->assertSame( 404, $response->get_status() );
    110110        }
    111111
     
    114114                $request  = new WP_REST_Request( 'POST', '/wp/v2/statuses/draft' );
    115115                $response = rest_get_server()->dispatch( $request );
    116                 $this->assertEquals( 404, $response->get_status() );
     116                $this->assertSame( 404, $response->get_status() );
    117117        }
    118118
     
    121121                $request  = new WP_REST_Request( 'DELETE', '/wp/v2/statuses/draft' );
    122122                $response = rest_get_server()->dispatch( $request );
    123                 $this->assertEquals( 404, $response->get_status() );
     123                $this->assertSame( 404, $response->get_status() );
    124124        }
    125125
     
    140140                $request->set_param( '_fields', 'id,name' );
    141141                $response = $endpoint->prepare_item_for_response( $obj, $request );
    142                 $this->assertEquals(
     142                $this->assertSame(
    143143                        array(
    144144                                // 'id' doesn't exist in this context.
     
    154154                $data       = $response->get_data();
    155155                $properties = $data['schema']['properties'];
    156                 $this->assertEquals( 8, count( $properties ) );
     156                $this->assertSame( 8, count( $properties ) );
    157157                $this->assertArrayHasKey( 'name', $properties );
    158158                $this->assertArrayHasKey( 'private', $properties );
     
    190190
    191191                $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
    192                 $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
     192                $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
    193193
    194194                $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/publish' );
     
    206206
    207207        protected function check_post_status_obj( $status_obj, $data, $links ) {
    208                 $this->assertEquals( $status_obj->label, $data['name'] );
    209                 $this->assertEquals( $status_obj->private, $data['private'] );
    210                 $this->assertEquals( $status_obj->protected, $data['protected'] );
    211                 $this->assertEquals( $status_obj->public, $data['public'] );
    212                 $this->assertEquals( $status_obj->publicly_queryable, $data['queryable'] );
    213                 $this->assertEquals( $status_obj->show_in_admin_all_list, $data['show_in_list'] );
    214                 $this->assertEquals( $status_obj->name, $data['slug'] );
     208                $this->assertSame( $status_obj->label, $data['name'] );
     209                $this->assertSame( $status_obj->private, $data['private'] );
     210                $this->assertSame( $status_obj->protected, $data['protected'] );
     211                $this->assertSame( $status_obj->public, $data['public'] );
     212                $this->assertSame( $status_obj->publicly_queryable, $data['queryable'] );
     213                $this->assertSame( $status_obj->show_in_admin_all_list, $data['show_in_list'] );
     214                $this->assertSame( $status_obj->name, $data['slug'] );
    215215                $this->assertEqualSets(
    216216                        array(
     
    219219                        array_keys( $links )
    220220                );
    221                 $this->assertEquals( $status_obj->date_floating, $data['date_floating'] );
     221                $this->assertSame( $status_obj->date_floating, $data['date_floating'] );
    222222        }
    223223
    224224        protected function check_post_status_object_response( $response ) {
    225                 $this->assertEquals( 200, $response->get_status() );
     225                $this->assertSame( 200, $response->get_status() );
    226226                $data = $response->get_data();
    227227                $obj  = get_post_status_object( 'publish' );
Note: See TracChangeset for help on using the changeset viewer.