Make WordPress Core

Changeset 57656

Timestamp:
02/19/2024 03:05:46 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in WP_REST_Navigation_Fallback_Controller 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 [56052].

See #59655.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php

    r56793 r57656  
    6262        $data     = $response->get_data();
    6363
    64         $this->assertEquals( 403, $response->get_status(), 'Response should indicate user does not have permission.' );
    65 
    66         $this->assertEquals( 'rest_cannot_create', $data['code'], 'Response should indicate user cannot create.' );
    67 
    68         $this->assertEquals( 'Sorry, you are not allowed to create Navigation Menus as this user.', $data['message'], 'Response should indicate failed request status.' );
     64        $this->assert( 403, $response->get_status(), 'Response should indicate user does not have permission.' );
     65
     66        $this->assert( 'rest_cannot_create', $data['code'], 'Response should indicate user cannot create.' );
     67
     68        $this->assert( 'Sorry, you are not allowed to create Navigation Menus as this user.', $data['message'], 'Response should indicate failed request status.' );
    6969    }
    7070
     
    8181        $data     = $response->get_data();
    8282
    83         $this->assertEquals( 200, $response->get_status(), 'Status should indicate successful request.' );
     83        $this->assert( 200, $response->get_status(), 'Status should indicate successful request.' );
    8484
    8585        $this->assertIsArray( $data, 'Response should be of correct type.' );
     
    8787        $this->assertArrayHasKey( 'id', $data, 'Response should contain expected fields.' );
    8888
    89         $this->assertEquals( 'wp_navigation', get_post_type( $data['id'] ), '"id" field should represent a post of type "wp_navigation"' );
     89        $this->assert( 'wp_navigation', get_post_type( $data['id'] ), '"id" field should represent a post of type "wp_navigation"' );
    9090
    9191        // Check that only a single Navigation fallback was created.
     
    106106        $data     = $response->get_data();
    107107
    108         $this->assertEquals( 200, $response->get_status(), 'Status should indicate successful request.' );
     108        $this->assert( 200, $response->get_status(), 'Status should indicate successful request.' );
    109109
    110110        $this->assertArrayHasKey( 'schema', $data, '"schema" key should exist in response.' );
     
    112112        $schema = $data['schema'];
    113113
    114         $this->assertEquals( 'object', $schema['type'], 'The schema type should match the expected type.' );
     114        $this->assert( 'object', $schema['type'], 'The schema type should match the expected type.' );
    115115
    116116        $this->assertArrayHasKey( 'id', $schema['properties'], 'Schema should have an "id" property.' );
    117         $this->assertEquals( 'integer', $schema['properties']['id']['type'], 'Schema "id" property should be an integer.' );
     117        $this->assert( 'integer', $schema['properties']['id']['type'], 'Schema "id" property should be an integer.' );
    118118        $this->assertTrue( $schema['properties']['id']['readonly'], 'Schema "id" property should be readonly.' );
    119119    }
Note: See TracChangeset for help on using the changeset viewer.