WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (15 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/admin/includesCommunityEvents.php

    r48576 r48937  
    165165        $this->assertNotWPError( $response );
    166166        $this->assertEqualSetsWithIndex( $this->get_user_location(), $response['location'] );
    167         $this->assertEquals( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $response['events'][0]['formatted_date'] );
    168         $this->assertEquals( '1:00 pm', $response['events'][0]['formatted_time'] );
     167        $this->assertSame( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $response['events'][0]['formatted_date'] );
     168        $this->assertSame( '1:00 pm', $response['events'][0]['formatted_time'] );
    169169
    170170        remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
     
    186186        $this->assertNotWPError( $cached_events );
    187187        $this->assertEqualSetsWithIndex( $this->get_user_location(), $cached_events['location'] );
    188         $this->assertEquals( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $cached_events['events'][0]['formatted_date'] );
    189         $this->assertEquals( '1:00 pm', $cached_events['events'][0]['formatted_time'] );
     188        $this->assertSame( gmdate( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $cached_events['events'][0]['formatted_date'] );
     189        $this->assertSame( '1:00 pm', $cached_events['events'][0]['formatted_time'] );
    190190
    191191        remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) );
     
    274274         */
    275275        $this->assertCount( 3, $response_body['events'] );
    276         $this->assertEquals( $response_body['events'][0]['title'], 'Flexbox + CSS Grid: Magic for Responsive Layouts' );
    277         $this->assertEquals( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
    278         $this->assertEquals( $response_body['events'][2]['title'], 'WordCamp San Diego' );
     276        $this->assertSame( $response_body['events'][0]['title'], 'Flexbox + CSS Grid: Magic for Responsive Layouts' );
     277        $this->assertSame( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
     278        $this->assertSame( $response_body['events'][2]['title'], 'WordCamp San Diego' );
    279279
    280280        remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response_unpinned_wordcamp' ) );
     
    376376         */
    377377        $this->assertCount( 3, $response_body['events'] );
    378         $this->assertEquals( $response_body['events'][0]['title'], 'WordCamp San Diego' );
    379         $this->assertEquals( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
    380         $this->assertEquals( $response_body['events'][2]['title'], 'WordPress Q&A' );
     378        $this->assertSame( $response_body['events'][0]['title'], 'WordCamp San Diego' );
     379        $this->assertSame( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' );
     380        $this->assertSame( $response_body['events'][2]['title'], 'WordPress Q&A' );
    381381
    382382        remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response_multiple_wordcamps' ) );
     
    489489        $actual_result             = WP_Community_Events::get_unsafe_client_ip();
    490490
    491         $this->assertEquals( $expected_result, $actual_result );
     491        $this->assertSame( $expected_result, $actual_result );
    492492    }
    493493
Note: See TracChangeset for help on using the changeset viewer.