Make WordPress Core

Changeset 59985


Ignore:
Timestamp:
03/15/2025 11:26:50 PM (2 months 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 [59630].

See #62278.

Location:
trunk/tests/phpunit/tests/rest-api
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php

    r59979 r59985  
    959959        $request->set_param( 'per_page', 1 );
    960960        $response = rest_get_server()->dispatch( $request );
    961         $this->assertEquals( 200, $response->get_status() );
     961        $this->assertSame( 200, $response->get_status() );
    962962        $data = $response->get_data();
    963963        $this->assertCount( 1, $data );
    964         $this->assertEquals( 3, $response->get_headers()['X-WP-Total'] );
    965         $this->assertEquals( 3, $response->get_headers()['X-WP-TotalPages'] );
     964        $this->assertSame( 3, $response->get_headers()['X-WP-Total'] );
     965        $this->assertSame( 3, $response->get_headers()['X-WP-TotalPages'] );
    966966
    967967        // Test paged.
     
    970970        $request->set_param( 'per_page', 2 );
    971971        $response = rest_get_server()->dispatch( $request );
    972         $this->assertEquals( 200, $response->get_status() );
     972        $this->assertSame( 200, $response->get_status() );
    973973        $data = $response->get_data();
    974974        $this->assertCount( 1, $data );
    975         $this->assertEquals( 3, $response->get_headers()['X-WP-Total'] );
    976         $this->assertEquals( 2, $response->get_headers()['X-WP-TotalPages'] );
     975        $this->assertSame( 3, $response->get_headers()['X-WP-Total'] );
     976        $this->assertSame( 2, $response->get_headers()['X-WP-TotalPages'] );
    977977
    978978        // Test out of bounds.
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r59979 r59985  
    59455945        $request->set_param( 'per_page', 1 );
    59465946        $response = rest_get_server()->dispatch( $request );
    5947         $this->assertEquals( 200, $response->get_status() );
     5947        $this->assertSame( 200, $response->get_status() );
    59485948        $data = $response->get_data();
    59495949        $this->assertCount( 1, $data );
    5950         $this->assertEquals( 30, $response->get_headers()['X-WP-Total'] );
    5951         $this->assertEquals( 30, $response->get_headers()['X-WP-TotalPages'] );
     5950        $this->assertSame( 30, $response->get_headers()['X-WP-Total'] );
     5951        $this->assertSame( 30, $response->get_headers()['X-WP-TotalPages'] );
    59525952
    59535953        // Test paged.
     
    59565956        $request->set_param( 'per_page', 2 );
    59575957        $response = rest_get_server()->dispatch( $request );
    5958         $this->assertEquals( 200, $response->get_status() );
     5958        $this->assertSame( 200, $response->get_status() );
    59595959        $data = $response->get_data();
    59605960        $this->assertCount( 2, $data );
    5961         $this->assertEquals( 30, $response->get_headers()['X-WP-Total'] );
    5962         $this->assertEquals( 15, $response->get_headers()['X-WP-TotalPages'] );
     5961        $this->assertSame( 30, $response->get_headers()['X-WP-Total'] );
     5962        $this->assertSame( 15, $response->get_headers()['X-WP-TotalPages'] );
    59635963
    59645964        // Test out of bounds.
  • trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php

    r59979 r59985  
    10581058        $request->set_param( 'per_page', 1 );
    10591059        $response = rest_get_server()->dispatch( $request );
    1060         $this->assertEquals( 200, $response->get_status() );
     1060        $this->assertSame( 200, $response->get_status() );
    10611061        $data = $response->get_data();
    10621062        $this->assertCount( 1, $data );
    1063         $this->assertEquals( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
    1064         $this->assertEquals( $this->total_revisions, $response->get_headers()['X-WP-TotalPages'] );
     1063        $this->assertSame( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
     1064        $this->assertSame( $this->total_revisions, $response->get_headers()['X-WP-TotalPages'] );
    10651065
    10661066        // Test paged.
     
    10691069        $request->set_param( 'per_page', 2 );
    10701070        $response = rest_get_server()->dispatch( $request );
    1071         $this->assertEquals( 200, $response->get_status() );
     1071        $this->assertSame( 200, $response->get_status() );
    10721072        $data = $response->get_data();
    10731073        $this->assertCount( 1, $data );
    1074         $this->assertEquals( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
    1075         $this->assertEquals( (int) ceil( $this->total_revisions / 2 ), $response->get_headers()['X-WP-TotalPages'] );
     1074        $this->assertSame( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
     1075        $this->assertSame( (int) ceil( $this->total_revisions / 2 ), $response->get_headers()['X-WP-TotalPages'] );
    10761076
    10771077        // Test out of bounds.
  • trunk/tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php

    r59979 r59985  
    11971197        $request->set_param( 'per_page', 1 );
    11981198        $response = rest_get_server()->dispatch( $request );
    1199         $this->assertEquals( 200, $response->get_status() );
     1199        $this->assertSame( 200, $response->get_status() );
    12001200        $data = $response->get_data();
    12011201        $this->assertCount( 1, $data );
    1202         $this->assertEquals( 4, $response->get_headers()['X-WP-Total'] );
    1203         $this->assertEquals( 4, $response->get_headers()['X-WP-TotalPages'] );
     1202        $this->assertSame( 4, $response->get_headers()['X-WP-Total'] );
     1203        $this->assertSame( 4, $response->get_headers()['X-WP-TotalPages'] );
    12041204
    12051205        // Test paged.
     
    12081208        $request->set_param( 'per_page', 2 );
    12091209        $response = rest_get_server()->dispatch( $request );
    1210         $this->assertEquals( 200, $response->get_status() );
     1210        $this->assertSame( 200, $response->get_status() );
    12111211        $data = $response->get_data();
    12121212        $this->assertCount( 2, $data );
    1213         $this->assertEquals( 4, $response->get_headers()['X-WP-Total'] );
    1214         $this->assertEquals( 2, $response->get_headers()['X-WP-TotalPages'] );
     1213        $this->assertSame( 4, $response->get_headers()['X-WP-Total'] );
     1214        $this->assertSame( 2, $response->get_headers()['X-WP-TotalPages'] );
    12151215
    12161216        // Test out of bounds.
Note: See TracChangeset for help on using the changeset viewer.