Make WordPress Core

Changeset 49547


Ignore:
Timestamp:
11/09/2020 03:43:14 PM (6 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.

Location:
trunk/tests/phpunit
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase-block-supports.php

    r49545 r49547  
    124124                $style_list   = $this->get_attribute_from_block( 'style', $styled_block );
    125125
    126                 $this->assertEquals( $expected_classes, $class_list );
    127                 $this->assertEquals( $expected_styles, $style_list );
     126                $this->assertSame( $expected_classes, $class_list );
     127                $this->assertSame( $expected_styles, $style_list );
    128128        }
    129129
     
    139139
    140140                // Ensure blocks to not add extra whitespace.
    141                 $this->assertEquals( $styled_block, trim( $styled_block ) );
     141                $this->assertSame( $styled_block, trim( $styled_block ) );
    142142
    143143                $content    = $this->get_content_from_block( $styled_block );
     
    145145                $style_list = $this->get_attribute_from_block( 'style', $styled_block );
    146146
    147                 $this->assertEquals( self::BLOCK_CONTENT, $content );
    148                 $this->assertEqualSets(
     147                $this->assertSame( self::BLOCK_CONTENT, $content );
     148                $this->assertSameSets(
    149149                        explode( ' ', $expected_classes ),
    150150                        explode( ' ', $class_list )
    151151                );
    152                 $this->assertEquals(
     152                $this->assertSame(
    153153                        array_map( 'trim', explode( ';', $expected_styles ) ),
    154154                        array_map( 'trim', explode( ';', $style_list ) )
  • trunk/tests/phpunit/tests/auth.php

    r49109 r49547  
    452452                $_SERVER['PHP_AUTH_PW']   = 'http_auth_pass';
    453453
    454                 $this->assertEquals(
    455                         0,
     454                $this->assertSame(
     455                        null,
    456456                        wp_validate_application_password( null ),
    457457                        'Regular user account password should not be allowed for API authentication'
     
    461461                $_SERVER['PHP_AUTH_PW'] = $user_app_password;
    462462
    463                 $this->assertEquals(
     463                $this->assertSame(
    464464                        $user_id,
    465465                        wp_validate_application_password( null ),
     
    492492                $error = wp_authenticate_application_password( null, 'idonotexist', 'password' );
    493493                $this->assertWPError( $error );
    494                 $this->assertEquals( 'invalid_username', $error->get_error_code() );
     494                $this->assertSame( 'invalid_username', $error->get_error_code() );
    495495        }
    496496
     
    503503                $error = wp_authenticate_application_password( null, 'idonotexist@example.org', 'password' );
    504504                $this->assertWPError( $error );
    505                 $this->assertEquals( 'invalid_email', $error->get_error_code() );
     505                $this->assertSame( 'invalid_email', $error->get_error_code() );
    506506        }
    507507
     
    515515                $error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
    516516                $this->assertWPError( $error );
    517                 $this->assertEquals( 'application_passwords_disabled', $error->get_error_code() );
     517                $this->assertSame( 'application_passwords_disabled', $error->get_error_code() );
    518518        }
    519519
     
    528528                $error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
    529529                $this->assertWPError( $error );
    530                 $this->assertEquals( 'application_passwords_disabled', $error->get_error_code() );
     530                $this->assertSame( 'application_passwords_disabled', $error->get_error_code() );
    531531        }
    532532
     
    540540                $error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
    541541                $this->assertWPError( $error );
    542                 $this->assertEquals( 'incorrect_password', $error->get_error_code() );
     542                $this->assertSame( 'incorrect_password', $error->get_error_code() );
    543543        }
    544544
     
    561561                $error = wp_authenticate_application_password( null, self::$_user->user_login, $password );
    562562                $this->assertWPError( $error );
    563                 $this->assertEquals( 'my_code', $error->get_error_code() );
     563                $this->assertSame( 'my_code', $error->get_error_code() );
    564564        }
    565565
     
    575575                $user = wp_authenticate_application_password( null, self::$_user->user_login, $password );
    576576                $this->assertInstanceOf( WP_User::class, $user );
    577                 $this->assertEquals( self::$user_id, $user->ID );
     577                $this->assertSame( self::$user_id, $user->ID );
    578578        }
    579579
     
    589589                $user = wp_authenticate_application_password( null, self::$_user->user_email, $password );
    590590                $this->assertInstanceOf( WP_User::class, $user );
    591                 $this->assertEquals( self::$user_id, $user->ID );
     591                $this->assertSame( self::$user_id, $user->ID );
    592592        }
    593593
     
    603603                $user = wp_authenticate_application_password( null, self::$_user->user_email, WP_Application_Passwords::chunk_password( $password ) );
    604604                $this->assertInstanceOf( WP_User::class, $user );
    605                 $this->assertEquals( self::$user_id, $user->ID );
     605                $this->assertSame( self::$user_id, $user->ID );
    606606        }
    607607}
  • trunk/tests/phpunit/tests/functions.php

    r49382 r49547  
    17641764         */
    17651765        public function test_wp_is_json_media_type( $input, $expected ) {
    1766                 $this->assertEquals( $expected, wp_is_json_media_type( $input ) );
     1766                $this->assertSame( $expected, wp_is_json_media_type( $input ) );
    17671767        }
    17681768
  • trunk/tests/phpunit/tests/multisite/site.php

    r49383 r49547  
    503503                        restore_current_blog();
    504504                        $this->assertNotEmpty( $spam_permalink );
    505                         $this->assertEquals( $post_data['post_title'], $post->post_title );
     505                        $this->assertSame( $post_data['post_title'], $post->post_title );
    506506
    507507                        update_blog_status( $spam_blog_id, 'spam', 1 );
  • 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'] );
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r49302 r49547  
    10291029
    10301030                $this->assertNotWPError( $response->as_error() );
    1031                 $this->assertEquals( 'inherit', $response->get_data()['status'] );
     1031                $this->assertSame( 'inherit', $response->get_data()['status'] );
    10321032        }
    10331033
  • trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r49303 r49547  
    14411441                $response = rest_get_server()->dispatch( $request );
    14421442                $this->assertSame( 201, $response->get_status() );
    1443                 $this->assertEquals( '0', $response->get_data()['content']['raw'] );
     1443                $this->assertSame( '0', $response->get_data()['content']['raw'] );
    14441444        }
    14451445
     
    14661466                $response = rest_get_server()->dispatch( $request );
    14671467                $this->assertSame( 201, $response->get_status() );
    1468                 $this->assertEquals( '', $response->get_data()['content']['raw'] );
     1468                $this->assertSame( '', $response->get_data()['content']['raw'] );
    14691469        }
    14701470
     
    33263326
    33273327                if ( $comment->comment_post_ID ) {
    3328                         $this->assertEquals( rest_url( '/wp/v2/posts/' . $comment->comment_post_ID ), $links['up'][0]['href'] );
     3328                        $this->assertSame( rest_url( '/wp/v2/posts/' . $comment->comment_post_ID ), $links['up'][0]['href'] );
    33293329                }
    33303330
  • trunk/tests/phpunit/tests/rest-api/rest-controller.php

    r49246 r49547  
    249249                $args       = rest_get_endpoint_args_for_schema( $controller->get_item_schema() );
    250250
    251                 $this->assertEquals( 'A pretty string.', $args['somestring']['description'] );
     251                $this->assertSame( 'A pretty string.', $args['somestring']['description'] );
    252252                $this->assertFalse( isset( $args['someinteger']['description'] ) );
    253253        }
  • trunk/tests/phpunit/tests/rest-api/rest-request.php

    r49329 r49547  
    206206
    207207                // Check that JSON takes precedence.
    208                 $this->assertEquals( $source, $this->request->get_param( 'source' ) );
     208                $this->assertSame( $source, $this->request->get_param( 'source' ) );
    209209                $this->assertEquals( $accept_json, $this->request->get_param( 'has_json_params' ) );
    210210        }
     
    234234
    235235                // Check for JSON content-type.
    236                 $this->assertEquals( $is_json, $this->request->is_json_content_type() );
     236                $this->assertSame( $is_json, $this->request->is_json_content_type() );
    237237        }
    238238
     
    927927                $valid = $request->has_valid_params();
    928928                $this->assertWPError( $valid );
    929                 $this->assertEquals( 'rest_invalid_param', $valid->get_error_code() );
     929                $this->assertSame( 'rest_invalid_param', $valid->get_error_code() );
    930930        }
    931931}
  • trunk/tests/phpunit/tests/rest-api/rest-search-controller.php

    r49365 r49547  
    570570                        )
    571571                );
    572                 $this->assertEquals( 200, $response->get_status() );
    573                 $this->assertEqualSets(
     572                $this->assertSame( 200, $response->get_status() );
     573                $this->assertSameSets(
    574574                        array(
    575575                                0 => 1, // That is the default category.
     
    595595                );
    596596
    597                 $this->assertEquals( 200, $response->get_status() );
    598                 $this->assertEqualSets(
     597                $this->assertSame( 200, $response->get_status() );
     598                $this->assertSameSets(
    599599                        array(
    600600                                0 => 1, // That is the default category.
     
    635635                        )
    636636                );
    637                 $this->assertEquals( 200, $response->get_status() );
    638                 $this->assertEqualSets(
     637                $this->assertSame( 200, $response->get_status() );
     638                $this->assertSameSets(
    639639                        array(
    640640                                0 => 1, // This is the default category.
     
    660660                );
    661661
    662                 $this->assertEquals( 200, $response->get_status() );
    663                 $this->assertEqualSets(
     662                $this->assertSame( 200, $response->get_status() );
     663                $this->assertSameSets(
    664664                        array(
    665665                                self::$my_category_id,
     
    683683                );
    684684
    685                 $this->assertEquals( 200, $response->get_status() );
    686                 $this->assertEqualSets(
     685                $this->assertSame( 200, $response->get_status() );
     686                $this->assertSameSets(
    687687                        array(
    688688                                self::$my_tag_id,
     
    706706                );
    707707
    708                 $this->assertEquals( 200, $response->get_status() );
     708                $this->assertSame( 200, $response->get_status() );
    709709                $this->assertEmpty( $response->get_data() );
    710710        }
     
    722722                        )
    723723                );
    724                 $this->assertEquals( 200, $response->get_status() );
     724                $this->assertSame( 200, $response->get_status() );
    725725                $this->assertContains(
    726726                        'Aside',
     
    743743                );
    744744
    745                 $this->assertEquals( 200, $response->get_status() );
     745                $this->assertSame( 200, $response->get_status() );
    746746                $this->assertContains(
    747747                        'Aside',
     
    765765                );
    766766
    767                 $this->assertEquals( 200, $response->get_status() );
     767                $this->assertSame( 200, $response->get_status() );
    768768                $this->assertEmpty( $response->get_data() );
    769769        }
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r49257 r49547  
    15511551                $this->assertCount( 1, $events );
    15521552                $this->assertWPError( $events[0]['args'][0] );
    1553                 $this->assertEquals( 'rest_invalid_handler', $events[0]['args'][0]->get_error_code() );
     1553                $this->assertSame( 'rest_invalid_handler', $events[0]['args'][0]->get_error_code() );
    15541554        }
    15551555
     
    16151615                $this->assertCount( 1, $events );
    16161616                $this->assertWPError( $events[0]['args'][0] );
    1617                 $this->assertEquals( 'rest_invalid_param', $events[0]['args'][0]->get_error_code() );
     1617                $this->assertSame( 'rest_invalid_param', $events[0]['args'][0]->get_error_code() );
    16181618        }
    16191619
     
    16541654                $response = rest_do_request( $request );
    16551655
    1656                 $this->assertEquals( 207, $response->get_status() );
     1656                $this->assertSame( 207, $response->get_status() );
    16571657
    16581658                if ( $allowed ) {
    1659                         $this->assertEquals( 'data', $response->get_data()['responses'][0]['body'] );
     1659                        $this->assertSame( 'data', $response->get_data()['responses'][0]['body'] );
    16601660                } else {
    1661                         $this->assertEquals( 'rest_batch_not_allowed', $response->get_data()['responses'][0]['body']['code'] );
     1661                        $this->assertSame( 'rest_batch_not_allowed', $response->get_data()['responses'][0]['body']['code'] );
    16621662                }
    16631663        }
     
    17241724                $data     = $response->get_data();
    17251725
    1726                 $this->assertEquals( 207, $response->get_status() );
     1726                $this->assertSame( 207, $response->get_status() );
    17271727                $this->assertArrayHasKey( 'failed', $data );
    1728                 $this->assertEquals( 'validation', $data['failed'] );
     1728                $this->assertSame( 'validation', $data['failed'] );
    17291729                $this->assertCount( 2, $data['responses'] );
    17301730                $this->assertNull( $data['responses'][0] );
    1731                 $this->assertEquals( 400, $data['responses'][1]['status'] );
     1731                $this->assertSame( 400, $data['responses'][1]['status'] );
    17321732                $this->assertFalse( get_option( 'test_project' ) );
    17331733        }
     
    17801780                $data     = $response->get_data();
    17811781
    1782                 $this->assertEquals( 207, $response->get_status() );
     1782                $this->assertSame( 207, $response->get_status() );
    17831783                $this->assertArrayNotHasKey( 'failed', $data );
    17841784                $this->assertCount( 2, $data['responses'] );
    1785                 $this->assertEquals( 'gutenberg', $data['responses'][0]['body'] );
    1786                 $this->assertEquals( 'WordPress', $data['responses'][1]['body'] );
     1785                $this->assertSame( 'gutenberg', $data['responses'][0]['body'] );
     1786                $this->assertSame( 'WordPress', $data['responses'][1]['body'] );
    17871787        }
    17881788
     
    17971797                                'methods'             => array( 'POST', 'DELETE' ),
    17981798                                'callback'            => function ( WP_REST_Request $request ) {
    1799                                         $this->assertEquals( 'DELETE', $request->get_method() );
    1800                                         $this->assertEquals( '/test-ns/v1/test/5', $request->get_route() );
    1801                                         $this->assertEquals( array( 'id' => '5' ), $request->get_url_params() );
    1802                                         $this->assertEquals( array( 'query' => 'param' ), $request->get_query_params() );
    1803                                         $this->assertEquals( array( 'project' => 'gutenberg' ), $request->get_body_params() );
    1804                                         $this->assertEquals( array( 'my_header' => array( 'my-value' ) ), $request->get_headers() );
     1799                                        $this->assertSame( 'DELETE', $request->get_method() );
     1800                                        $this->assertSame( '/test-ns/v1/test/5', $request->get_route() );
     1801                                        $this->assertSame( array( 'id' => '5' ), $request->get_url_params() );
     1802                                        $this->assertSame( array( 'query' => 'param' ), $request->get_query_params() );
     1803                                        $this->assertSame( array( 'project' => 'gutenberg' ), $request->get_body_params() );
     1804                                        $this->assertSame( array( 'my_header' => array( 'my-value' ) ), $request->get_headers() );
    18051805
    18061806                                        return new WP_REST_Response( 'test' );
     
    18311831                $response = rest_get_server()->dispatch( $request );
    18321832
    1833                 $this->assertEquals( 207, $response->get_status() );
    1834                 $this->assertEquals( 'test', $response->get_data()['responses'][0]['body'] );
     1833                $this->assertSame( 207, $response->get_status() );
     1834                $this->assertSame( 'test', $response->get_data()['responses'][0]['body'] );
    18351835        }
    18361836
     
    18841884                $data     = $response->get_data();
    18851885
    1886                 $this->assertEquals( 207, $response->get_status() );
     1886                $this->assertSame( 207, $response->get_status() );
    18871887                $this->assertArrayNotHasKey( 'failed', $data );
    18881888                $this->assertCount( 2, $data['responses'] );
    1889                 $this->assertEquals( 'gutenberg', $data['responses'][0]['body'] );
    1890                 $this->assertEquals( 400, $data['responses'][1]['status'] );
    1891                 $this->assertEquals( 'gutenberg', get_option( 'test_project' ) );
     1889                $this->assertSame( 'gutenberg', $data['responses'][0]['body'] );
     1890                $this->assertSame( 400, $data['responses'][1]['status'] );
     1891                $this->assertSame( 'gutenberg', get_option( 'test_project' ) );
    18921892        }
    18931893
     
    19291929
    19301930                $response = rest_get_server()->dispatch( $request );
    1931                 $this->assertEquals( 400, $response->get_status() );
     1931                $this->assertSame( 400, $response->get_status() );
    19321932        }
    19331933
  • trunk/tests/phpunit/tests/rest-api/rest-site-health-controller.php

    r49156 r49547  
    9898                wp_set_current_user( self::$admin );
    9999                $response = rest_do_request( '/wp-site-health/v1/tests/dotorg-communication' );
    100                 $this->assertEquals( 'dotorg_communication', $response->get_data()['test'] );
     100                $this->assertSame( 'dotorg_communication', $response->get_data()['test'] );
    101101        }
    102102}
Note: See TracChangeset for help on using the changeset viewer.