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

    r47122 r48937  
    4444        $comment = get_comment( $id );
    4545
    46         $this->assertEquals( wp_unslash( $this->slash_1 ), $comment->comment_author );
    47         $this->assertEquals( wp_unslash( $this->slash_7 ), $comment->comment_content );
     46        $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );
     47        $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );
    4848
    4949        $data = array(
     
    5959        $comment = get_comment( $id );
    6060
    61         $this->assertEquals( wp_unslash( $this->slash_2 ), $comment->comment_author );
    62         $this->assertEquals( wp_unslash( $this->slash_4 ), $comment->comment_content );
     61        $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );
     62        $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );
    6363    }
    6464
     
    8989        $comment = get_comment( $comment_id );
    9090
    91         $this->assertEquals( $this->slash_1, $comment->comment_author );
    92         $this->assertEquals( $this->slash_7, $comment->comment_content );
     91        $this->assertSame( $this->slash_1, $comment->comment_author );
     92        $this->assertSame( $this->slash_7, $comment->comment_content );
    9393
    9494        $_POST                            = array();
     
    105105        $comment = get_comment( $comment_id );
    106106
    107         $this->assertEquals( $this->slash_2, $comment->comment_author );
    108         $this->assertEquals( $this->slash_4, $comment->comment_content );
     107        $this->assertSame( $this->slash_2, $comment->comment_author );
     108        $this->assertSame( $this->slash_4, $comment->comment_content );
    109109    }
    110110
     
    124124        $comment    = get_comment( $comment_id );
    125125
    126         $this->assertEquals( wp_unslash( $this->slash_1 ), $comment->comment_author );
    127         $this->assertEquals( wp_unslash( $this->slash_7 ), $comment->comment_content );
     126        $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );
     127        $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );
    128128
    129129        $comment_id = wp_insert_comment(
     
    136136        $comment    = get_comment( $comment_id );
    137137
    138         $this->assertEquals( wp_unslash( $this->slash_2 ), $comment->comment_author );
    139         $this->assertEquals( wp_unslash( $this->slash_4 ), $comment->comment_content );
     138        $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );
     139        $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );
    140140    }
    141141
     
    160160        $comment = get_comment( $comment_id );
    161161
    162         $this->assertEquals( wp_unslash( $this->slash_1 ), $comment->comment_author );
    163         $this->assertEquals( wp_unslash( $this->slash_7 ), $comment->comment_content );
     162        $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );
     163        $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );
    164164
    165165        wp_update_comment(
     
    172172        $comment = get_comment( $comment_id );
    173173
    174         $this->assertEquals( wp_unslash( $this->slash_2 ), $comment->comment_author );
    175         $this->assertEquals( wp_unslash( $this->slash_4 ), $comment->comment_content );
     174        $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );
     175        $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );
    176176    }
    177177
Note: See TracChangeset for help on using the changeset viewer.