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/general/archives.php

    r46586 r48937  
    3333        $time1 = wp_cache_get( 'last_changed', 'posts' );
    3434        $this->assertNotEmpty( $time1 );
    35         $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     35        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    3636
    3737        $num_queries = $wpdb->num_queries;
     
    4545        );
    4646        $this->assertInternalType( 'string', $result );
    47         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    48         $this->assertEquals( $num_queries, $wpdb->num_queries );
     47        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     48        $this->assertSame( $num_queries, $wpdb->num_queries );
    4949
    5050        // Change args, resulting in a different query string. Cache is not primed, expect 1 query.
     
    5757        );
    5858        $this->assertInternalType( 'string', $result );
    59         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    60         $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     59        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     60        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    6161
    6262        $num_queries = $wpdb->num_queries;
     
    7171        );
    7272        $this->assertInternalType( 'string', $result );
    73         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    74         $this->assertEquals( $num_queries, $wpdb->num_queries );
     73        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     74        $this->assertSame( $num_queries, $wpdb->num_queries );
    7575
    7676        $num_queries = $wpdb->num_queries;
     
    8484        );
    8585        $this->assertInternalType( 'string', $result );
    86         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    87         $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     86        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     87        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    8888
    8989        $num_queries = $wpdb->num_queries;
     
    9797        );
    9898        $this->assertInternalType( 'string', $result );
    99         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    100         $this->assertEquals( $num_queries, $wpdb->num_queries );
     99        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     100        $this->assertSame( $num_queries, $wpdb->num_queries );
    101101
    102102        // Change type. Cache is not primed, expect 1 query.
     
    108108        );
    109109        $this->assertInternalType( 'string', $result );
    110         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    111         $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     110        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     111        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    112112
    113113        $num_queries = $wpdb->num_queries;
     
    121121        );
    122122        $this->assertInternalType( 'string', $result );
    123         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    124         $this->assertEquals( $num_queries, $wpdb->num_queries );
     123        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     124        $this->assertSame( $num_queries, $wpdb->num_queries );
    125125
    126126        // Change type. Cache is not primed, expect 1 query.
     
    132132        );
    133133        $this->assertInternalType( 'string', $result );
    134         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    135         $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     134        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     135        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    136136
    137137        $num_queries = $wpdb->num_queries;
     
    145145        );
    146146        $this->assertInternalType( 'string', $result );
    147         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    148         $this->assertEquals( $num_queries, $wpdb->num_queries );
     147        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     148        $this->assertSame( $num_queries, $wpdb->num_queries );
    149149
    150150        // Change type. Cache is not primed, expect 1 query.
     
    156156        );
    157157        $this->assertInternalType( 'string', $result );
    158         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    159         $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     158        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     159        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    160160
    161161        $num_queries = $wpdb->num_queries;
     
    169169        );
    170170        $this->assertInternalType( 'string', $result );
    171         $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    172         $this->assertEquals( $num_queries, $wpdb->num_queries );
     171        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
     172        $this->assertSame( $num_queries, $wpdb->num_queries );
    173173    }
    174174}
Note: See TracChangeset for help on using the changeset viewer.