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.php

    r48235 r48937  
    5353            )
    5454        );
    55         $this->assertEquals( 1, $result );
     55        $this->assertSame( 1, $result );
    5656
    5757        $comment = get_comment( $comments[0] );
     
    6464            )
    6565        );
    66         $this->assertEquals( 0, $result );
     66        $this->assertSame( 0, $result );
    6767
    6868        $result = wp_update_comment(
     
    9191
    9292        $comment = get_comment( $comment_id );
    93         $this->assertEquals( 'pingback', $comment->comment_type );
     93        $this->assertSame( 'pingback', $comment->comment_type );
    9494    }
    9595
     
    110110        );
    111111
    112         $this->assertEquals( 'fire', get_comment_meta( $comment_id, 'sauce', true ) );
     112        $this->assertSame( 'fire', get_comment_meta( $comment_id, 'sauce', true ) );
    113113    }
    114114
     
    148148
    149149        $comment = get_comment( $comment_id );
    150         $this->assertEquals( $updated_comment_text, $comment->comment_content );
     150        $this->assertSame( $updated_comment_text, $comment->comment_content );
    151151    }
    152152
     
    163163            )
    164164        );
    165         $this->assertSame( false, $update );
     165        $this->assertFalse( $update );
    166166
    167167        $update = wp_update_comment(
     
    171171            )
    172172        );
    173         $this->assertSame( false, $update );
     173        $this->assertFalse( $update );
    174174    }
    175175
     
    291291        $comment = get_comment( $id );
    292292
    293         $this->assertEquals( $data['comment_date'], $comment->comment_date );
    294         $this->assertEquals( $data['comment_date_gmt'], $comment->comment_date_gmt );
     293        $this->assertSame( $data['comment_date'], $comment->comment_date );
     294        $this->assertSame( $data['comment_date_gmt'], $comment->comment_date_gmt );
    295295    }
    296296
     
    313313        $comment = get_comment( $id );
    314314
    315         $this->assertEquals( $data['comment_author_IP'], $comment->comment_author_IP );
     315        $this->assertSame( $data['comment_author_IP'], $comment->comment_author_IP );
    316316    }
    317317
     
    334334        $comment = get_comment( $id );
    335335
    336         $this->assertEquals( $data['comment_author_IP'], $comment->comment_author_IP );
     336        $this->assertSame( $data['comment_author_IP'], $comment->comment_author_IP );
    337337    }
    338338
     
    356356        $comment = get_comment( $id );
    357357
    358         $this->assertEquals( $data['comment_agent'], $comment->comment_agent );
     358        $this->assertSame( $data['comment_agent'], $comment->comment_agent );
    359359    }
    360360
     
    378378        $comment = get_comment( $id );
    379379
    380         $this->assertEquals( 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16 Mozilla/5.0 (Macintosh; U; PPC Mac OS ', $comment->comment_agent );
     380        $this->assertSame( 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16 Mozilla/5.0 (Macintosh; U; PPC Mac OS ', $comment->comment_agent );
    381381    }
    382382
     
    400400        $comment = get_comment( $id );
    401401
    402         $this->assertEquals( $data['comment_agent'], $comment->comment_agent );
     402        $this->assertSame( $data['comment_agent'], $comment->comment_agent );
    403403    }
    404404
     
    420420        $comment = get_comment( $id );
    421421
    422         $this->assertEquals( strlen( $comment->comment_content ), 65535 );
     422        $this->assertSame( strlen( $comment->comment_content ), 65535 );
    423423    }
    424424
     
    569569        );
    570570
    571         $this->assertEquals( 'fire', get_comment_meta( $c, 'sauce', true ) );
     571        $this->assertSame( 'fire', get_comment_meta( $c, 'sauce', true ) );
    572572    }
    573573
Note: See TracChangeset for help on using the changeset viewer.