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

    r47122 r48937  
    723723        );
    724724
    725         $this->assertEquals( array( $c2 ), $found );
     725        $this->assertSame( array( $c2 ), $found );
    726726    }
    727727
     
    759759        );
    760760
    761         $this->assertEquals( array( $c2 ), $found );
     761        $this->assertSame( array( $c2 ), $found );
    762762    }
    763763
     
    875875        );
    876876
    877         $this->assertEquals( array( $c2 ), $found );
     877        $this->assertSame( array( $c2 ), $found );
    878878    }
    879879
     
    911911        );
    912912
    913         $this->assertEquals( array( $c2 ), $found );
     913        $this->assertSame( array( $c2 ), $found );
    914914    }
    915915
     
    10171017        );
    10181018
    1019         $this->assertEquals( array( $c2 ), $found );
     1019        $this->assertSame( array( $c2 ), $found );
    10201020    }
    10211021
     
    10451045        );
    10461046
    1047         $this->assertEquals( array( $c1 ), $found );
     1047        $this->assertSame( array( $c1 ), $found );
    10481048    }
    10491049
     
    10761076        );
    10771077
    1078         $this->assertEquals( array( $c2 ), $found );
     1078        $this->assertSame( array( $c2 ), $found );
    10791079    }
    10801080
     
    12941294        $post_id = self::factory()->post->create();
    12951295        self::factory()->comment->create_post_comments( $post_id, $limit );
     1296
    12961297        $comments = get_comments( array( 'post_id' => $post_id ) );
    1297         $this->assertEquals( $limit, count( $comments ) );
     1298        $this->assertSame( $limit, count( $comments ) );
    12981299        foreach ( $comments as $comment ) {
    12991300            $this->assertEquals( $post_id, $comment->comment_post_ID );
     
    13021303        $post_id2 = self::factory()->post->create();
    13031304        self::factory()->comment->create_post_comments( $post_id2, $limit );
     1305
    13041306        $comments = get_comments( array( 'post_id' => $post_id2 ) );
    1305         $this->assertEquals( $limit, count( $comments ) );
     1307        $this->assertSame( $limit, count( $comments ) );
    13061308        foreach ( $comments as $comment ) {
    13071309            $this->assertEquals( $post_id2, $comment->comment_post_ID );
     
    13101312        $post_id3 = self::factory()->post->create();
    13111313        self::factory()->comment->create_post_comments( $post_id3, $limit, array( 'comment_approved' => '0' ) );
     1314
    13121315        $comments = get_comments( array( 'post_id' => $post_id3 ) );
    1313         $this->assertEquals( $limit, count( $comments ) );
     1316        $this->assertSame( $limit, count( $comments ) );
    13141317        foreach ( $comments as $comment ) {
    13151318            $this->assertEquals( $post_id3, $comment->comment_post_ID );
     
    13221325            )
    13231326        );
    1324         $this->assertEquals( $limit, count( $comments ) );
     1327        $this->assertSame( $limit, count( $comments ) );
    13251328        foreach ( $comments as $comment ) {
    13261329            $this->assertEquals( $post_id3, $comment->comment_post_ID );
     
    13331336            )
    13341337        );
    1335         $this->assertEquals( 0, count( $comments ) );
     1338        $this->assertSame( 0, count( $comments ) );
    13361339
    13371340        self::factory()->comment->create_post_comments( $post_id3, $limit, array( 'comment_approved' => '1' ) );
    13381341        $comments = get_comments( array( 'post_id' => $post_id3 ) );
    1339         $this->assertEquals( $limit * 2, count( $comments ) );
     1342        $this->assertSame( $limit * 2, count( $comments ) );
    13401343        foreach ( $comments as $comment ) {
    13411344            $this->assertEquals( $post_id3, $comment->comment_post_ID );
     
    13641367            )
    13651368        );
    1366         $this->assertEquals( 2, count( $comments ) );
     1369        $this->assertSame( 2, count( $comments ) );
    13671370        $this->assertEquals( $comment_id2, $comments[0]->comment_ID );
    13681371        $this->assertEquals( $comment_id, $comments[1]->comment_ID );
     
    13741377            )
    13751378        );
    1376         $this->assertEquals( 2, count( $comments ) );
     1379        $this->assertSame( 2, count( $comments ) );
    13771380        $this->assertEquals( $comment_id2, $comments[0]->comment_ID );
    13781381        $this->assertEquals( $comment_id, $comments[1]->comment_ID );
     
    13851388            )
    13861389        );
    1387         $this->assertEquals( 2, count( $comments ) );
     1390        $this->assertSame( 2, count( $comments ) );
    13881391        $this->assertEquals( $comment_id, $comments[0]->comment_ID );
    13891392        $this->assertEquals( $comment_id2, $comments[1]->comment_ID );
     
    13961399            )
    13971400        );
    1398         $this->assertEquals( 2, count( $comments ) );
     1401        $this->assertSame( 2, count( $comments ) );
    13991402        $this->assertEquals( $comment_id, $comments[0]->comment_ID );
    14001403        $this->assertEquals( $comment_id2, $comments[1]->comment_ID );
     
    14241427            )
    14251428        );
    1426         $this->assertEquals( 1, count( $comments ) );
     1429        $this->assertSame( 1, count( $comments ) );
    14271430
    14281431        $comments = get_comments(
     
    14321435            )
    14331436        );
    1434         $this->assertEquals( 1, count( $comments ) );
     1437        $this->assertSame( 1, count( $comments ) );
    14351438    }
    14361439
     
    14591462        );
    14601463
    1461         $this->assertEquals( array( $comments[1], $comments[2], $comments[0] ), $found );
     1464        $this->assertSame( array( $comments[1], $comments[2], $comments[0] ), $found );
    14621465    }
    14631466
     
    15031506        );
    15041507
    1505         $this->assertEquals( array( $c3, $c1, $c2 ), $found );
     1508        $this->assertSame( array( $c3, $c1, $c2 ), $found );
    15061509    }
    15071510
     
    15401543        );
    15411544
    1542         $this->assertEquals( array( $comments[2], $comments[0], $comments[1] ), $found );
     1545        $this->assertSame( array( $comments[2], $comments[0], $comments[1] ), $found );
    15431546    }
    15441547
     
    15661569        );
    15671570
    1568         $this->assertEquals( array( $comments[2] ), $q->get_comments() );
     1571        $this->assertSame( array( $comments[2] ), $q->get_comments() );
    15691572    }
    15701573
     
    15921595        );
    15931596
    1594         $this->assertEquals( array( $comments[0] ), $q->get_comments() );
     1597        $this->assertSame( array( $comments[0] ), $q->get_comments() );
    15951598    }
    15961599
     
    28972900        );
    28982901
    2899         $this->assertEquals( 2, $found );
     2902        $this->assertSame( 2, $found );
    29002903    }
    29012904
     
    29382941        );
    29392942
    2940         $this->assertEquals( 2, $found );
     2943        $this->assertSame( 2, $found );
    29412944    }
    29422945
     
    36733676        );
    36743677
    3675         $this->assertEquals( array( $c2, $c3 ), $ids->comments );
     3678        $this->assertSame( array( $c2, $c3 ), $ids->comments );
    36763679
    36773680    }
     
    36903693        );
    36913694
    3692         $this->assertEquals( 0, $q->found_comments );
    3693         $this->assertEquals( 0, $q->max_num_pages );
     3695        $this->assertSame( 0, $q->found_comments );
     3696        $this->assertSame( 0, $q->max_num_pages );
    36943697    }
    36953698
     
    37083711        );
    37093712
    3710         $this->assertEquals( 0, $q->found_comments );
    3711         $this->assertEquals( 0, $q->max_num_pages );
     3713        $this->assertSame( 0, $q->found_comments );
     3714        $this->assertSame( 0, $q->max_num_pages );
    37123715    }
    37133716
     
    37263729        );
    37273730
    3728         $this->assertEquals( 3, $q->found_comments );
     3731        $this->assertSame( 3, $q->found_comments );
    37293732        $this->assertEquals( 2, $q->max_num_pages );
    37303733    }
     
    37963799        );
    37973800
    3798         $this->assertEquals( array( $top_level_comments[0], $top_level_comments[1] ), $q->comments );
     3801        $this->assertSame( array( $top_level_comments[0], $top_level_comments[1] ), $q->comments );
    37993802    }
    38003803
     
    46774680            )
    46784681        );
    4679         $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
     4682        $this->assertSame( $number_of_queries + 1, $wpdb->num_queries );
    46804683    }
    46814684
     
    47064709            )
    47074710        );
    4708         $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     4711        $this->assertSame( $number_of_queries, $wpdb->num_queries );
    47094712    }
    47104713
     
    47344737        );
    47354738
    4736         $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     4739        $this->assertSame( $number_of_queries, $wpdb->num_queries );
    47374740    }
    47384741
     
    49064909
    49074910        // Make sure manually setting total_users doesn't get overwritten.
    4908         $this->assertEquals( 1, $q->found_comments );
     4911        $this->assertSame( 1, $q->found_comments );
    49094912    }
    49104913
Note: See TracChangeset for help on using the changeset viewer.