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/user/slashes.php

    r47122 r48937  
    4747        $user = get_user_to_edit( $id );
    4848
    49         $this->assertEquals( $this->slash_1, $user->first_name );
    50         $this->assertEquals( $this->slash_3, $user->last_name );
    51         $this->assertEquals( $this->slash_5, $user->nickname );
    52         $this->assertEquals( $this->slash_7, $user->display_name );
    53         $this->assertEquals( $this->slash_3, $user->description );
     49        $this->assertSame( $this->slash_1, $user->first_name );
     50        $this->assertSame( $this->slash_3, $user->last_name );
     51        $this->assertSame( $this->slash_5, $user->nickname );
     52        $this->assertSame( $this->slash_7, $user->display_name );
     53        $this->assertSame( $this->slash_3, $user->description );
    5454
    5555        $_POST                 = array();
     
    7272        $user = get_user_to_edit( $id );
    7373
    74         $this->assertEquals( $this->slash_2, $user->first_name );
    75         $this->assertEquals( $this->slash_4, $user->last_name );
    76         $this->assertEquals( $this->slash_6, $user->nickname );
    77         $this->assertEquals( $this->slash_2, $user->display_name );
    78         $this->assertEquals( $this->slash_4, $user->description );
     74        $this->assertSame( $this->slash_2, $user->first_name );
     75        $this->assertSame( $this->slash_4, $user->last_name );
     76        $this->assertSame( $this->slash_6, $user->nickname );
     77        $this->assertSame( $this->slash_2, $user->display_name );
     78        $this->assertSame( $this->slash_4, $user->description );
    7979    }
    8080
     
    101101        $user = get_user_to_edit( $id );
    102102
    103         $this->assertEquals( $this->slash_1, $user->first_name );
    104         $this->assertEquals( $this->slash_3, $user->last_name );
    105         $this->assertEquals( $this->slash_5, $user->nickname );
    106         $this->assertEquals( $this->slash_7, $user->display_name );
    107         $this->assertEquals( $this->slash_3, $user->description );
     103        $this->assertSame( $this->slash_1, $user->first_name );
     104        $this->assertSame( $this->slash_3, $user->last_name );
     105        $this->assertSame( $this->slash_5, $user->nickname );
     106        $this->assertSame( $this->slash_7, $user->display_name );
     107        $this->assertSame( $this->slash_3, $user->description );
    108108
    109109        $_POST                 = array();
     
    123123        $user = get_user_to_edit( $id );
    124124
    125         $this->assertEquals( $this->slash_2, $user->first_name );
    126         $this->assertEquals( $this->slash_4, $user->last_name );
    127         $this->assertEquals( $this->slash_6, $user->nickname );
    128         $this->assertEquals( $this->slash_2, $user->display_name );
    129         $this->assertEquals( $this->slash_4, $user->description );
     125        $this->assertSame( $this->slash_2, $user->first_name );
     126        $this->assertSame( $this->slash_4, $user->last_name );
     127        $this->assertSame( $this->slash_6, $user->nickname );
     128        $this->assertSame( $this->slash_2, $user->display_name );
     129        $this->assertSame( $this->slash_4, $user->description );
    130130    }
    131131
     
    149149        $user = get_user_to_edit( $id );
    150150
    151         $this->assertEquals( wp_unslash( $this->slash_1 ), $user->first_name );
    152         $this->assertEquals( wp_unslash( $this->slash_3 ), $user->last_name );
    153         $this->assertEquals( wp_unslash( $this->slash_5 ), $user->nickname );
    154         $this->assertEquals( wp_unslash( $this->slash_7 ), $user->display_name );
    155         $this->assertEquals( wp_unslash( $this->slash_3 ), $user->description );
     151        $this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );
     152        $this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );
     153        $this->assertSame( wp_unslash( $this->slash_5 ), $user->nickname );
     154        $this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );
     155        $this->assertSame( wp_unslash( $this->slash_3 ), $user->description );
    156156
    157157        $id   = wp_insert_user(
     
    170170        $user = get_user_to_edit( $id );
    171171
    172         $this->assertEquals( wp_unslash( $this->slash_2 ), $user->first_name );
    173         $this->assertEquals( wp_unslash( $this->slash_4 ), $user->last_name );
    174         $this->assertEquals( wp_unslash( $this->slash_6 ), $user->nickname );
    175         $this->assertEquals( wp_unslash( $this->slash_2 ), $user->display_name );
    176         $this->assertEquals( wp_unslash( $this->slash_4 ), $user->description );
     172        $this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );
     173        $this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );
     174        $this->assertSame( wp_unslash( $this->slash_6 ), $user->nickname );
     175        $this->assertSame( wp_unslash( $this->slash_2 ), $user->display_name );
     176        $this->assertSame( wp_unslash( $this->slash_4 ), $user->description );
    177177    }
    178178
     
    195195        $user = get_user_to_edit( $id );
    196196
    197         $this->assertEquals( wp_unslash( $this->slash_1 ), $user->first_name );
    198         $this->assertEquals( wp_unslash( $this->slash_3 ), $user->last_name );
    199         $this->assertEquals( wp_unslash( $this->slash_5 ), $user->nickname );
    200         $this->assertEquals( wp_unslash( $this->slash_7 ), $user->display_name );
    201         $this->assertEquals( wp_unslash( $this->slash_3 ), $user->description );
     197        $this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );
     198        $this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );
     199        $this->assertSame( wp_unslash( $this->slash_5 ), $user->nickname );
     200        $this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );
     201        $this->assertSame( wp_unslash( $this->slash_3 ), $user->description );
    202202
    203203        $id   = wp_update_user(
     
    214214        $user = get_user_to_edit( $id );
    215215
    216         $this->assertEquals( wp_unslash( $this->slash_2 ), $user->first_name );
    217         $this->assertEquals( wp_unslash( $this->slash_4 ), $user->last_name );
    218         $this->assertEquals( wp_unslash( $this->slash_6 ), $user->nickname );
    219         $this->assertEquals( wp_unslash( $this->slash_2 ), $user->display_name );
    220         $this->assertEquals( wp_unslash( $this->slash_4 ), $user->description );
     216        $this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );
     217        $this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );
     218        $this->assertSame( wp_unslash( $this->slash_6 ), $user->nickname );
     219        $this->assertSame( wp_unslash( $this->slash_2 ), $user->display_name );
     220        $this->assertSame( wp_unslash( $this->slash_4 ), $user->description );
    221221    }
    222222
Note: See TracChangeset for help on using the changeset viewer.