WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit 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.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/CustomizeMenus.php

    r48858 r48937  
    550550
    551551        if ( isset( $post_args['search'] ) && 'test' === $post_args['search'] ) {
    552             $this->assertsame( true, $response['success'] );
     552            $this->assertTrue( $response['success'] );
    553553            $this->assertSame( 6, count( $response['data']['items'] ) );
    554554            $item_ids = wp_list_pluck( $response['data']['items'], 'id' );
     
    629629        $this->assertArrayHasKey( 'url', $response['data'] );
    630630        $post = get_post( $response['data']['post_id'] );
    631         $this->assertEquals( 'Hello World', $post->post_title );
    632         $this->assertEquals( 'post', $post->post_type );
    633         $this->assertEquals( '', $post->post_name );
    634         $this->assertEquals( 'hello-world', get_post_meta( $post->ID, '_customize_draft_post_name', true ) );
    635         $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $post->ID, '_customize_changeset_uuid', true ) );
     631        $this->assertSame( 'Hello World', $post->post_title );
     632        $this->assertSame( 'post', $post->post_type );
     633        $this->assertSame( '', $post->post_name );
     634        $this->assertSame( 'hello-world', get_post_meta( $post->ID, '_customize_draft_post_name', true ) );
     635        $this->assertSame( $this->wp_customize->changeset_uuid(), get_post_meta( $post->ID, '_customize_changeset_uuid', true ) );
    636636    }
    637637
     
    648648        $response = json_decode( $this->_last_response, true );
    649649        $this->assertFalse( $response['success'] );
    650         $this->assertEquals( 'bad_nonce', $response['data'] );
     650        $this->assertSame( 'bad_nonce', $response['data'] );
    651651
    652652        // Bad nonce.
     
    660660        $response = json_decode( $this->_last_response, true );
    661661        $this->assertFalse( $response['success'] );
    662         $this->assertEquals( 'bad_nonce', $response['data'] );
     662        $this->assertSame( 'bad_nonce', $response['data'] );
    663663
    664664        // Bad nonce.
     
    673673        $response = json_decode( $this->_last_response, true );
    674674        $this->assertFalse( $response['success'] );
    675         $this->assertEquals( 'customize_not_allowed', $response['data'] );
     675        $this->assertSame( 'customize_not_allowed', $response['data'] );
    676676
    677677        // Missing params.
     
    686686        $response = json_decode( $this->_last_response, true );
    687687        $this->assertFalse( $response['success'] );
    688         $this->assertEquals( 'missing_params', $response['data'] );
     688        $this->assertSame( 'missing_params', $response['data'] );
    689689
    690690        // insufficient_post_permissions.
     
    702702        $response = json_decode( $this->_last_response, true );
    703703        $this->assertFalse( $response['success'] );
    704         $this->assertEquals( 'insufficient_post_permissions', $response['data'] );
     704        $this->assertSame( 'insufficient_post_permissions', $response['data'] );
    705705
    706706        // insufficient_post_permissions.
     
    717717        $response = json_decode( $this->_last_response, true );
    718718        $this->assertFalse( $response['success'] );
    719         $this->assertEquals( 'missing_post_type_param', $response['data'] );
     719        $this->assertSame( 'missing_post_type_param', $response['data'] );
    720720
    721721        // missing_post_title.
     
    733733        $response = json_decode( $this->_last_response, true );
    734734        $this->assertFalse( $response['success'] );
    735         $this->assertEquals( 'missing_post_title', $response['data'] );
     735        $this->assertSame( 'missing_post_title', $response['data'] );
    736736
    737737        // illegal_params.
     
    751751        $response = json_decode( $this->_last_response, true );
    752752        $this->assertFalse( $response['success'] );
    753         $this->assertEquals( 'illegal_params', $response['data'] );
     753        $this->assertSame( 'illegal_params', $response['data'] );
    754754    }
    755755}
Note: See TracChangeset for help on using the changeset viewer.