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/rest-api/rest-controller.php

    r48796 r48937  
    107107
    108108        // Check sanitize testing.
    109         $this->assertEquals(
     109        $this->assertSame(
    110110            false,
    111111            rest_sanitize_request_arg( 'false', $this->request, 'someboolean' )
    112112        );
    113         $this->assertEquals(
     113        $this->assertSame(
    114114            false,
    115115            rest_sanitize_request_arg( '0', $this->request, 'someboolean' )
    116116        );
    117         $this->assertEquals(
     117        $this->assertSame(
    118118            false,
    119119            rest_sanitize_request_arg( 0, $this->request, 'someboolean' )
    120120        );
    121         $this->assertEquals(
     121        $this->assertSame(
    122122            false,
    123123            rest_sanitize_request_arg( 'FALSE', $this->request, 'someboolean' )
    124124        );
    125         $this->assertEquals(
     125        $this->assertSame(
    126126            true,
    127127            rest_sanitize_request_arg( 'true', $this->request, 'someboolean' )
    128128        );
    129         $this->assertEquals(
     129        $this->assertSame(
    130130            true,
    131131            rest_sanitize_request_arg( '1', $this->request, 'someboolean' )
    132132        );
    133         $this->assertEquals(
     133        $this->assertSame(
    134134            true,
    135135            rest_sanitize_request_arg( 1, $this->request, 'someboolean' )
    136136        );
    137         $this->assertEquals(
     137        $this->assertSame(
    138138            true,
    139139            rest_sanitize_request_arg( 'TRUE', $this->request, 'someboolean' )
     
    226226        $controller = new WP_REST_Test_Controller();
    227227        $args       = $controller->get_endpoint_args_for_item_schema();
    228         $this->assertEquals( 'A pretty string.', $args['somestring']['description'] );
     228        $this->assertSame( 'A pretty string.', $args['somestring']['description'] );
    229229        $this->assertFalse( isset( $args['someinteger']['description'] ) );
    230230    }
     
    236236
    237237        $this->assertFalse( $args['someargoptions']['required'] );
    238         $this->assertEquals( '__return_true', $args['someargoptions']['sanitize_callback'] );
     238        $this->assertSame( '__return_true', $args['someargoptions']['sanitize_callback'] );
    239239    }
    240240
     
    245245        $args = $controller->get_endpoint_args_for_item_schema();
    246246
    247         $this->assertEquals( 'a', $args['somedefault']['default'] );
     247        $this->assertSame( 'a', $args['somedefault']['default'] );
    248248    }
    249249
     
    286286        $request    = new WP_REST_Request( 'GET', '/wp/v2/testroute' );
    287287        $fields     = $controller->get_fields_for_response( $request );
    288         $this->assertEquals(
     288        $this->assertSame(
    289289            array(
    290290                'somestring',
     
    306306        $request->set_param( '_fields', $param );
    307307        $fields = $controller->get_fields_for_response( $request );
    308         $this->assertEquals( $expected, $fields );
     308        $this->assertSame( $expected, $fields );
    309309    }
    310310
     
    537537        $response = rest_filter_response_fields( $response, rest_get_server(), $request );
    538538
    539         $this->assertEquals( $expected, $response->get_data() );
     539        $this->assertSame( $expected, $response->get_data() );
    540540    }
    541541
Note: See TracChangeset for help on using the changeset viewer.