Make WordPress Core


Ignore:
Timestamp:
11/09/2020 03:43:14 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in some newly introduced 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.

Follow-up to [48937], [48939], [48940], [48944].

See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php

    r49276 r49547  
    135135
    136136        $response = rest_do_request( '/wp/v2/users/me/application-passwords' );
    137         $this->assertEquals( 200, $response->get_status() );
     137        $this->assertSame( 200, $response->get_status() );
    138138        $this->assertCount( 1, $response->get_data() );
    139139        $this->check_response( $response->get_data()[0], $item );
     
    148148
    149149        $response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords', self::$admin ) );
    150         $this->assertEquals( 200, $response->get_status() );
     150        $this->assertSame( 200, $response->get_status() );
    151151        $this->assertCount( 1, $response->get_data() );
    152152        $this->check_response( $response->get_data()[0], $item );
     
    161161
    162162        $response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
    163         $this->assertEquals( 200, $response->get_status() );
     163        $this->assertSame( 200, $response->get_status() );
    164164        $this->assertCount( 1, $response->get_data() );
    165165        $this->check_response( $response->get_data()[0], $item );
     
    174174
    175175        $response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
    176         $this->assertEquals( 200, $response->get_status() );
     176        $this->assertSame( 200, $response->get_status() );
    177177        $this->assertCount( 1, $response->get_data() );
    178178        $this->check_response( $response->get_data()[0], $item );
     
    216216        $uuid     = $item['uuid'];
    217217        $response = rest_do_request( '/wp/v2/users/me/application-passwords/' . $uuid );
    218         $this->assertEquals( 200, $response->get_status() );
     218        $this->assertSame( 200, $response->get_status() );
    219219        $this->check_response( $response->get_data(), $item );
    220220    }
     
    229229        $uuid     = $item['uuid'];
    230230        $response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$admin, $uuid ) );
    231         $this->assertEquals( 200, $response->get_status() );
     231        $this->assertSame( 200, $response->get_status() );
    232232        $this->check_response( $response->get_data(), $item );
    233233    }
     
    242242        $uuid     = $item['uuid'];
    243243        $response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
    244         $this->assertEquals( 200, $response->get_status() );
     244        $this->assertSame( 200, $response->get_status() );
    245245        $this->check_response( $response->get_data(), $item );
    246246    }
     
    255255        $uuid     = $item['uuid'];
    256256        $response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
    257         $this->assertEquals( 200, $response->get_status() );
     257        $this->assertSame( 200, $response->get_status() );
    258258        $this->check_response( $response->get_data(), $item );
    259259    }
     
    319319        $response = rest_do_request( $request );
    320320
    321         $this->assertEquals( 201, $response->get_status() );
     321        $this->assertSame( 201, $response->get_status() );
    322322
    323323        $passwords = WP_Application_Passwords::get_user_application_passwords( self::$admin );
    324324        $this->assertCount( 1, $passwords );
    325325        $this->check_response( $response->get_data(), $passwords[0], true );
    326         $this->assertEquals( 'App', $response->get_data()['name'] );
    327         $this->assertEquals( $app_id, $response->get_data()['app_id'] );
     326        $this->assertSame( 'App', $response->get_data()['name'] );
     327        $this->assertSame( $app_id, $response->get_data()['app_id'] );
    328328        $this->assertNull( $response->get_data()['last_used'] );
    329329        $this->assertNull( $response->get_data()['last_ip'] );
     
    340340        $response = rest_do_request( $request );
    341341
    342         $this->assertEquals( 201, $response->get_status() );
     342        $this->assertSame( 201, $response->get_status() );
    343343
    344344        $passwords = WP_Application_Passwords::get_user_application_passwords( self::$admin );
     
    357357        $response = rest_do_request( $request );
    358358
    359         $this->assertEquals( 201, $response->get_status() );
     359        $this->assertSame( 201, $response->get_status() );
    360360
    361361        $passwords = WP_Application_Passwords::get_user_application_passwords( self::$subscriber_id );
     
    374374        $response = rest_do_request( $request );
    375375
    376         $this->assertEquals( 201, $response->get_status() );
     376        $this->assertSame( 201, $response->get_status() );
    377377
    378378        $passwords = WP_Application_Passwords::get_user_application_passwords( self::$subscriber_id );
     
    416416        $request->set_body_params( array( 'name' => 'New App' ) );
    417417        $response = rest_do_request( $request );
    418         $this->assertEquals( 200, $response->get_status() );
     418        $this->assertSame( 200, $response->get_status() );
    419419        $this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$admin, $item['uuid'] ) );
    420         $this->assertEquals( 'New App', $response->get_data()['name'] );
     420        $this->assertSame( 'New App', $response->get_data()['name'] );
    421421    }
    422422
     
    432432        $request->set_body_params( array( 'name' => 'New App' ) );
    433433        $response = rest_do_request( $request );
    434         $this->assertEquals( 200, $response->get_status() );
     434        $this->assertSame( 200, $response->get_status() );
    435435        $this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$admin, $item['uuid'] ) );
    436         $this->assertEquals( 'New App', $response->get_data()['name'] );
     436        $this->assertSame( 'New App', $response->get_data()['name'] );
    437437    }
    438438
     
    448448        $request->set_body_params( array( 'name' => 'New App' ) );
    449449        $response = rest_do_request( $request );
    450         $this->assertEquals( 200, $response->get_status() );
     450        $this->assertSame( 200, $response->get_status() );
    451451        $this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$subscriber_id, $item['uuid'] ) );
    452         $this->assertEquals( 'New App', $response->get_data()['name'] );
     452        $this->assertSame( 'New App', $response->get_data()['name'] );
    453453    }
    454454
     
    464464        $request->set_body_params( array( 'name' => 'New App' ) );
    465465        $response = rest_do_request( $request );
    466         $this->assertEquals( 200, $response->get_status() );
     466        $this->assertSame( 200, $response->get_status() );
    467467        $this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$subscriber_id, $item['uuid'] ) );
    468         $this->assertEquals( 'New App', $response->get_data()['name'] );
     468        $this->assertSame( 'New App', $response->get_data()['name'] );
    469469    }
    470470
     
    532532        $request->set_body_params( array( 'app_id' => wp_generate_uuid4() ) );
    533533        $response = rest_do_request( $request );
    534         $this->assertEquals( '', $response->get_data()['app_id'] );
     534        $this->assertSame( '', $response->get_data()['app_id'] );
    535535
    536536        $app_id = wp_generate_uuid4();
     
    548548        $request->set_body_params( array( 'app_id' => wp_generate_uuid4() ) );
    549549        $response = rest_do_request( $request );
    550         $this->assertEquals( $app_id, $response->get_data()['app_id'] );
     550        $this->assertSame( $app_id, $response->get_data()['app_id'] );
    551551    }
    552552
     
    561561        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/users/me/application-passwords/' . $uuid );
    562562        $response = rest_do_request( $request );
    563         $this->assertEquals( 200, $response->get_status() );
     563        $this->assertSame( 200, $response->get_status() );
    564564        $this->assertArrayHasKey( 'deleted', $response->get_data() );
    565565        $this->assertTrue( $response->get_data()['deleted'] );
     
    580580        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$admin, $uuid ) );
    581581        $response = rest_do_request( $request );
    582         $this->assertEquals( 200, $response->get_status() );
     582        $this->assertSame( 200, $response->get_status() );
    583583        $this->check_response( $response->get_data()['previous'], $item );
    584584    }
     
    594594        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
    595595        $response = rest_do_request( $request );
    596         $this->assertEquals( 200, $response->get_status() );
     596        $this->assertSame( 200, $response->get_status() );
    597597        $this->check_response( $response->get_data()['previous'], $item );
    598598    }
     
    608608        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
    609609        $response = rest_do_request( $request );
    610         $this->assertEquals( 200, $response->get_status() );
     610        $this->assertSame( 200, $response->get_status() );
    611611        $this->check_response( $response->get_data()['previous'], $item );
    612612    }
     
    670670        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/users/me/application-passwords' );
    671671        $response = rest_do_request( $request );
    672         $this->assertEquals( 200, $response->get_status() );
     672        $this->assertSame( 200, $response->get_status() );
    673673        $this->assertArrayHasKey( 'deleted', $response->get_data() );
    674674        $this->assertTrue( $response->get_data()['deleted'] );
    675675        $this->assertArrayHasKey( 'count', $response->get_data() );
    676         $this->assertEquals( 2, $response->get_data()['count'] );
     676        $this->assertSame( 2, $response->get_data()['count'] );
    677677
    678678        $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
     
    688688        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords', self::$admin ) );
    689689        $response = rest_do_request( $request );
    690         $this->assertEquals( 200, $response->get_status() );
     690        $this->assertSame( 200, $response->get_status() );
    691691        $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
    692692    }
     
    701701        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
    702702        $response = rest_do_request( $request );
    703         $this->assertEquals( 200, $response->get_status() );
     703        $this->assertSame( 200, $response->get_status() );
    704704        $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
    705705    }
     
    714714        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
    715715        $response = rest_do_request( $request );
    716         $this->assertEquals( 200, $response->get_status() );
     716        $this->assertSame( 200, $response->get_status() );
    717717        $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
    718718    }
     
    819819        $this->assertArrayHasKey( 'last_ip', $response );
    820820
    821         $this->assertEquals( $item['uuid'], $response['uuid'] );
    822         $this->assertEquals( $item['app_id'], $response['app_id'] );
    823         $this->assertEquals( $item['name'], $response['name'] );
    824         $this->assertEquals( gmdate( 'Y-m-d\TH:i:s', $item['created'] ), $response['created'] );
     821        $this->assertSame( $item['uuid'], $response['uuid'] );
     822        $this->assertSame( $item['app_id'], $response['app_id'] );
     823        $this->assertSame( $item['name'], $response['name'] );
     824        $this->assertSame( gmdate( 'Y-m-d\TH:i:s', $item['created'] ), $response['created'] );
    825825
    826826        if ( $item['last_used'] ) {
    827             $this->assertEquals( gmdate( 'Y-m-d\TH:i:s', $item['last_used'] ), $response['last_used'] );
     827            $this->assertSame( gmdate( 'Y-m-d\TH:i:s', $item['last_used'] ), $response['last_used'] );
    828828        } else {
    829829            $this->assertNull( $response['last_used'] );
     
    831831
    832832        if ( $item['last_ip'] ) {
    833             $this->assertEquals( $item['last_ip'], $response['last_ip'] );
     833            $this->assertSame( $item['last_ip'], $response['last_ip'] );
    834834        } else {
    835835            $this->assertNull( $response['last_ip'] );
Note: See TracChangeset for help on using the changeset viewer.