Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (6 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/getPageOfComment.php

    r48133 r48937  
    2929                $comment_first = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-14 00:00:00' ) );
    3030
    31                 $this->assertEquals( 4, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) );
    32                 $this->assertEquals( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 10 ) ) );
    33 
    34                 $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 3 ) ) );
    35                 $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 10 ) ) );
     31                $this->assertSame( 4, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) );
     32                $this->assertSame( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 10 ) ) );
     33
     34                $this->assertSame( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 3 ) ) );
     35                $this->assertSame( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 10 ) ) );
    3636        }
    3737
     
    6464                }
    6565
    66                 $this->assertEquals(
     66                $this->assertSame(
    6767                        2,
    6868                        get_page_of_comment(
     
    7474                        )
    7575                );
    76                 $this->assertEquals(
     76                $this->assertSame(
    7777                        3,
    7878                        get_page_of_comment(
     
    8484                        )
    8585                );
    86                 $this->assertEquals(
     86                $this->assertSame(
    8787                        5,
    8888                        get_page_of_comment(
     
    149149                        )
    150150                );
    151                 $this->assertEquals( 2, $page_trackbacks );
     151                $this->assertSame( 2, $page_trackbacks );
    152152
    153153                $num_queries   = $wpdb->num_queries;
     
    159159                        )
    160160                );
    161                 $this->assertEquals( 1, $page_comments );
     161                $this->assertSame( 1, $page_comments );
    162162
    163163                $this->assertNotEquals( $num_queries, $wpdb->num_queries );
     
    244244                );
    245245
    246                 $this->assertEquals( 1, get_page_of_comment( $c1, array( 'per_page' => 2 ) ) );
     246                $this->assertSame( 1, get_page_of_comment( $c1, array( 'per_page' => 2 ) ) );
    247247
    248248                wp_set_comment_status( $c3, '1' );
    249249
    250                 $this->assertEquals( 2, get_page_of_comment( $c1, array( 'per_page' => 2 ) ) );
     250                $this->assertSame( 2, get_page_of_comment( $c1, array( 'per_page' => 2 ) ) );
    251251        }
    252252
     
    276276
    277277                $found_0 = get_page_of_comment( $comments_0[0], array( 'per_page' => 2 ) );
    278                 $this->assertEquals( 3, $found_0 );
     278                $this->assertSame( 3, $found_0 );
    279279
    280280                $found_1 = get_page_of_comment( $comments_1[1], array( 'per_page' => 2 ) );
    281                 $this->assertEquals( 2, $found_1 );
     281                $this->assertSame( 2, $found_1 );
    282282        }
    283283
     
    358358                update_option( 'comments_per_page', 2 );
    359359
    360                 $this->assertEquals( 2, get_page_of_comment( $c1 ) );
     360                $this->assertSame( 2, get_page_of_comment( $c1 ) );
    361361        }
    362362
     
    398398                update_option( 'comments_per_page', 1 );
    399399
    400                 $this->assertEquals( 2, get_page_of_comment( $c3 ) );
     400                $this->assertSame( 2, get_page_of_comment( $c3 ) );
    401401        }
    402402
     
    438438                update_option( 'comments_per_page', 1 );
    439439
    440                 $this->assertEquals( 2, get_page_of_comment( $c3 ) );
     440                $this->assertSame( 2, get_page_of_comment( $c3 ) );
    441441        }
    442442
Note: See TracChangeset for help on using the changeset viewer.