Make WordPress Core

Changeset 61373


Ignore:
Timestamp:
12/12/2025 09:36:52 PM (8 hours 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 [61032], [61045].

See #64324.

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

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php

    r61130 r61373  
    172172
    173173        $data = $response->get_data();
    174         $this->assertEquals( 'test-data-retrieval', $data['slug'] );
    175         $this->assertEquals( 'Data Retrieval', $data['label'] );
    176         $this->assertEquals( 'Abilities that retrieve and return data from the WordPress site.', $data['description'] );
     174        $this->assertSame( 'test-data-retrieval', $data['slug'] );
     175        $this->assertSame( 'Data Retrieval', $data['label'] );
     176        $this->assertSame( 'Abilities that retrieve and return data from the WordPress site.', $data['description'] );
    177177        $this->assertArrayHasKey( 'meta', $data );
    178178    }
     
    190190
    191191        $data = $response->get_data();
    192         $this->assertEquals( 'test-communication', $data['slug'] );
     192        $this->assertSame( 'test-communication', $data['slug'] );
    193193        $this->assertArrayHasKey( 'meta', $data );
    194194        $this->assertIsArray( $data['meta'] );
    195         $this->assertEquals( 'high', $data['meta']['priority'] );
     195        $this->assertSame( 'high', $data['meta']['priority'] );
    196196    }
    197197
     
    213213        $data = $response->get_data();
    214214        $this->assertCount( 2, $data, 'Response should only contain the requested fields.' );
    215         $this->assertEquals( 'test-data-retrieval', $data['slug'] );
    216         $this->assertEquals( 'Data Retrieval', $data['label'] );
     215        $this->assertSame( 'test-data-retrieval', $data['slug'] );
     216        $this->assertSame( 'Data Retrieval', $data['label'] );
    217217    }
    218218
     
    231231
    232232        $data = $response->get_data();
    233         $this->assertEquals( 'rest_ability_category_not_found', $data['code'] );
     233        $this->assertSame( 'rest_ability_category_not_found', $data['code'] );
    234234    }
    235235
     
    425425        $schema = $data['schema'];
    426426
    427         $this->assertEquals( 'ability-category', $schema['title'] );
    428         $this->assertEquals( 'object', $schema['type'] );
     427        $this->assertSame( 'ability-category', $schema['title'] );
     428        $this->assertSame( 'object', $schema['type'] );
    429429        $this->assertArrayHasKey( 'properties', $schema );
    430430
     
    439439
    440440        $slug_property = $properties['slug'];
    441         $this->assertEquals( 'string', $slug_property['type'] );
     441        $this->assertSame( 'string', $slug_property['type'] );
    442442        $this->assertTrue( $slug_property['readonly'] );
    443443    }
  • trunk/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php

    r61130 r61373  
    308308        $data = $response->get_data();
    309309        $this->assertCount( 7, $data, 'Response should contain all fields.' );
    310         $this->assertEquals( 'test/calculator', $data['name'] );
    311         $this->assertEquals( 'Calculator', $data['label'] );
    312         $this->assertEquals( 'Performs basic calculations', $data['description'] );
    313         $this->assertEquals( 'math', $data['category'] );
     310        $this->assertSame( 'test/calculator', $data['name'] );
     311        $this->assertSame( 'Calculator', $data['label'] );
     312        $this->assertSame( 'Performs basic calculations', $data['description'] );
     313        $this->assertSame( 'math', $data['category'] );
    314314        $this->assertArrayHasKey( 'input_schema', $data );
    315315        $this->assertArrayHasKey( 'output_schema', $data );
     
    335335        $data = $response->get_data();
    336336        $this->assertCount( 2, $data, 'Response should only contain the requested fields.' );
    337         $this->assertEquals( 'test/calculator', $data['name'] );
    338         $this->assertEquals( 'Calculator', $data['label'] );
     337        $this->assertSame( 'test/calculator', $data['name'] );
     338        $this->assertSame( 'Calculator', $data['label'] );
    339339    }
    340340
     
    356356        $data = $response->get_data();
    357357        $this->assertCount( 3, $data, 'Response should only contain the fields for embed context.' );
    358         $this->assertEquals( 'test/calculator', $data['name'] );
    359         $this->assertEquals( 'Calculator', $data['label'] );
    360         $this->assertEquals( 'math', $data['category'] );
     358        $this->assertSame( 'test/calculator', $data['name'] );
     359        $this->assertSame( 'Calculator', $data['label'] );
     360        $this->assertSame( 'math', $data['category'] );
    361361    }
    362362
     
    375375
    376376        $data = $response->get_data();
    377         $this->assertEquals( 'rest_ability_not_found', $data['code'] );
     377        $this->assertSame( 'rest_ability_not_found', $data['code'] );
    378378    }
    379379
     
    390390
    391391        $data = $response->get_data();
    392         $this->assertEquals( 'rest_ability_not_found', $data['code'] );
     392        $this->assertSame( 'rest_ability_not_found', $data['code'] );
    393393    }
    394394
     
    582582        $schema = $data['schema'];
    583583
    584         $this->assertEquals( 'ability', $schema['title'] );
    585         $this->assertEquals( 'object', $schema['type'] );
     584        $this->assertSame( 'ability', $schema['title'] );
     585        $this->assertSame( 'object', $schema['type'] );
    586586        $this->assertArrayHasKey( 'properties', $schema );
    587587
     
    746746        // Should only have math category abilities
    747747        foreach ( $data as $ability ) {
    748             $this->assertEquals( 'math', $ability['category'], 'All abilities should be in math category' );
     748            $this->assertSame( 'math', $ability['category'], 'All abilities should be in math category' );
    749749        }
    750750
  • trunk/tests/phpunit/tests/rest-api/wpRestAbilitiesV1RunController.php

    r61130 r61373  
    473473
    474474        $this->assertEquals( 200, $response->get_status() );
    475         $this->assertEquals( 'User successfully deleted!', $response->get_data() );
     475        $this->assertSame( 'User successfully deleted!', $response->get_data() );
    476476    }
    477477
     
    631631        $response = $this->server->dispatch( $request );
    632632        $this->assertEquals( 200, $response->get_status() );
    633         $this->assertEquals( 'Success: test data', $response->get_data() );
     633        $this->assertSame( 'Success: test data', $response->get_data() );
    634634    }
    635635
     
    647647        $this->assertEquals( 404, $response->get_status() );
    648648        $data = $response->get_data();
    649         $this->assertEquals( 'rest_ability_not_found', $data['code'] );
    650         $this->assertEquals( 'Ability not found.', $data['message'] );
     649        $this->assertSame( 'rest_ability_not_found', $data['code'] );
     650        $this->assertSame( 'Ability not found.', $data['message'] );
    651651    }
    652652
     
    680680        $this->assertEquals( 500, $response->get_status() );
    681681        $data = $response->get_data();
    682         $this->assertEquals( 'test_error', $data['code'] );
    683         $this->assertEquals( 'This is a test error', $data['message'] );
     682        $this->assertSame( 'test_error', $data['code'] );
     683        $this->assertSame( 'This is a test error', $data['message'] );
    684684    }
    685685
     
    699699        $this->assertEquals( 404, $response->get_status() );
    700700        $data = $response->get_data();
    701         $this->assertEquals( 'rest_ability_not_found', $data['code'] );
     701        $this->assertSame( 'rest_ability_not_found', $data['code'] );
    702702    }
    703703
     
    715715        $schema = $data['schema'];
    716716
    717         $this->assertEquals( 'ability-execution', $schema['title'] );
    718         $this->assertEquals( 'object', $schema['type'] );
     717        $this->assertSame( 'ability-execution', $schema['title'] );
     718        $this->assertSame( 'object', $schema['type'] );
    719719        $this->assertArrayHasKey( 'properties', $schema );
    720720        $this->assertArrayHasKey( 'result', $schema['properties'] );
     
    762762
    763763        $data = $response->get_data();
    764         $this->assertEquals( 'nested', $data['level1']['level2']['value'] );
     764        $this->assertSame( 'nested', $data['level1']['level2']['value'] );
    765765        $this->assertEquals( array( 1, 2, 3 ), $data['array'] );
    766766    }
Note: See TracChangeset for help on using the changeset viewer.