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-request-validation.php

    r46586 r48937  
    2727        );
    2828        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    29         $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
    30         $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
    31         $this->assertTrue( $ret );
    32         $ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
    33         $this->assertTrue( $ret );
    34         $ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
    35         $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
     29        $this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
     30        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
     31        $this->assertTrue( $ret );
     32        $ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
     33        $this->assertTrue( $ret );
     34        $ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
     35        $this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
    3636    }
    3737
     
    5252        );
    5353        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    54         $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
    55         $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
    56         $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
     54        $this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
     55        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
     56        $this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
    5757        $ret = rest_validate_request_arg( 3, $request, 'minmaxrange' );
    5858        $this->assertTrue( $ret );
     
    6262        $this->assertTrue( $ret );
    6363        $ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
    64         $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
     64        $this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
    6565    }
    6666
     
    8181        );
    8282        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    83         $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
     83        $this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
    8484        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
    8585        $this->assertTrue( $ret );
     
    8989        $this->assertTrue( $ret );
    9090        $ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
    91         $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
    92         $ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
    93         $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
     91        $this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
     92        $ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
     93        $this->assertSame( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
    9494    }
    9595
     
    111111        );
    112112        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    113         $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
    114         $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
    115         $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
     113        $this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
     114        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
     115        $this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
    116116        $ret = rest_validate_request_arg( 3, $request, 'minmaxrange' );
    117117        $this->assertTrue( $ret );
     
    119119        $this->assertTrue( $ret );
    120120        $ret = rest_validate_request_arg( 10, $request, 'minmaxrange' );
    121         $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
    122         $ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
    123         $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
     121        $this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
     122        $ret = rest_validate_request_arg( 11, $request, 'minmaxrange' );
     123        $this->assertSame( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
    124124    }
    125125
     
    138138        );
    139139        $ret     = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
    140         $this->assertEquals( 'greaterthanmin must be greater than or equal to 2', $ret->get_error_message() );
     140        $this->assertSame( 'greaterthanmin must be greater than or equal to 2', $ret->get_error_message() );
    141141        $ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
    142142        $this->assertTrue( $ret );
     
    158158        );
    159159        $ret     = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
    160         $this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
     160        $this->assertSame( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
    161161        $ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
    162         $this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
     162        $this->assertSame( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
    163163        $ret = rest_validate_request_arg( 3, $request, 'greaterthanmin' );
    164164        $this->assertTrue( $ret );
     
    179179        );
    180180        $ret     = rest_validate_request_arg( 11, $request, 'lessthanmax' );
    181         $this->assertEquals( 'lessthanmax must be less than or equal to 10', $ret->get_error_message() );
     181        $this->assertSame( 'lessthanmax must be less than or equal to 10', $ret->get_error_message() );
    182182        $ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
    183183        $this->assertTrue( $ret );
     
    199199        );
    200200        $ret     = rest_validate_request_arg( 11, $request, 'lessthanmax' );
    201         $this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() );
     201        $this->assertSame( 'lessthanmax must be less than 10', $ret->get_error_message() );
    202202        $ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
    203         $this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() );
     203        $this->assertSame( 'lessthanmax must be less than 10', $ret->get_error_message() );
    204204        $ret = rest_validate_request_arg( 9, $request, 'lessthanmax' );
    205205        $this->assertTrue( $ret );
Note: See TracChangeset for help on using the changeset viewer.