Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years 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/query/dateQuery.php

    r47122 r48937  
    9797        );
    9898
    99         $this->assertEquals( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
     99        $this->assertSame( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
    100100    }
    101101
     
    142142        );
    143143
    144         $this->assertEquals( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
     144        $this->assertSame( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
    145145    }
    146146
     
    160160        );
    161161
    162         $this->assertEquals( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
     162        $this->assertSame( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
    163163    }
    164164
     
    179179        );
    180180
    181         $this->assertEquals( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
     181        $this->assertSame( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
    182182    }
    183183
     
    208208        );
    209209
    210         $this->assertEquals( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
     210        $this->assertSame( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
    211211    }
    212212
     
    248248        );
    249249
    250         $this->assertEquals( array( $p2 ), $before_posts );
    251         $this->assertEquals( array( $p1 ), $after_posts );
     250        $this->assertSame( array( $p2 ), $before_posts );
     251        $this->assertSame( array( $p1 ), $after_posts );
    252252    }
    253253
     
    332332        );
    333333
    334         $this->assertEquals( array( $p2 ), $before_posts );
    335         $this->assertEquals( array( $p1 ), $after_posts );
     334        $this->assertSame( array( $p2 ), $before_posts );
     335        $this->assertSame( array( $p1 ), $after_posts );
    336336    }
    337337
     
    416416        );
    417417
    418         $this->assertEquals( array( $p2 ), $before_posts );
    419         $this->assertEquals( array( $p1 ), $after_posts );
     418        $this->assertSame( array( $p2 ), $before_posts );
     419        $this->assertSame( array( $p1 ), $after_posts );
    420420    }
    421421
     
    500500        );
    501501
    502         $this->assertEquals( array( $p2 ), $before_posts );
    503         $this->assertEquals( array( $p1 ), $after_posts );
     502        $this->assertSame( array( $p2 ), $before_posts );
     503        $this->assertSame( array( $p1 ), $after_posts );
    504504    }
    505505
     
    584584        );
    585585
    586         $this->assertEquals( array( $p2 ), $before_posts );
    587         $this->assertEquals( array( $p1 ), $after_posts );
     586        $this->assertSame( array( $p2 ), $before_posts );
     587        $this->assertSame( array( $p1 ), $after_posts );
    588588    }
    589589
     
    668668        );
    669669
    670         $this->assertEquals( array( $p1, $p2 ), $before_posts );
     670        $this->assertSame( array( $p1, $p2 ), $before_posts );
    671671    }
    672672
     
    684684        );
    685685
    686         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     686        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    687687    }
    688688
     
    700700        );
    701701
    702         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     702        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    703703    }
    704704
     
    716716        );
    717717
    718         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     718        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    719719    }
    720720
     
    733733        );
    734734
    735         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     735        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    736736    }
    737737
     
    750750        );
    751751
    752         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     752        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    753753    }
    754754
     
    770770        );
    771771
    772         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     772        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    773773    }
    774774
     
    787787        );
    788788
    789         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     789        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    790790    }
    791791
     
    807807        );
    808808
    809         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     809        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    810810    }
    811811
     
    824824        );
    825825
    826         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     826        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    827827    }
    828828
     
    841841        );
    842842
    843         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     843        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    844844    }
    845845
     
    890890        );
    891891
    892         $this->assertEquals( array( $p1, $p3 ), wp_list_pluck( $posts, 'ID' ) );
     892        $this->assertSame( array( $p1, $p3 ), wp_list_pluck( $posts, 'ID' ) );
    893893    }
    894894
     
    911911        );
    912912
    913         $this->assertEquals( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
     913        $this->assertSame( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
    914914    }
    915915
     
    930930        );
    931931
    932         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     932        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    933933
    934934        $this->assertContains( "MONTH( $wpdb->posts.post_date ) = 5", $this->q->request );
     
    952952        );
    953953
    954         $this->assertEquals( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
     954        $this->assertSame( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
    955955
    956956        $this->assertContains( "WEEK( $wpdb->posts.post_date, 1 ) = 43", $this->q->request );
     
    993993        _unregister_taxonomy( 'foo' );
    994994
    995         $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     995        $this->assertSame( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    996996    }
    997997
     
    10241024        );
    10251025
    1026         $this->assertEquals( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
     1026        $this->assertSame( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
    10271027    }
    10281028
Note: See TracChangeset for help on using the changeset viewer.