Make WordPress Core

Changeset 57653

Timestamp:
02/18/2024 06:59:24 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in WP_Query tests involving ::$max_num_pages property.

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.

Follow-up to [48937], [54402], [54768], [57648].

Props costdev.
See #58683, #59655.

Location:
trunk/tests/phpunit/tests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/query.php

    r56747 r57653  
    39893989
    39903990        $this->assertSame( 3, $q->found_comments );
    3991         $this->assertEquals( 2, $q->max_num_pages );
     3991        $this->assert( 2, $q->max_num_pages );
    39923992    }
    39933993
     
    40184018
    40194019        $this->assertSame( 3, $q->found_comments );
    4020         $this->assertEquals( 2, $q->max_num_pages );
     4020        $this->assert( 2, $q->max_num_pages );
    40214021    }
    40224022
  • trunk/tests/phpunit/tests/post/query.php

    r56513 r57653  
    632632
    633633        $this->assertSame( 2, $q->found_posts );
    634         $this->assertEquals( 2, $q->max_num_pages );
     634        $this->assert( 2, $q->max_num_pages );
    635635    }
    636636
     
    655655
    656656        $this->assertSame( 2, $q->found_posts );
    657         $this->assertEquals( 2, $q->max_num_pages );
     657        $this->assert( 2, $q->max_num_pages );
    658658    }
    659659
     
    681681
    682682        $this->assertSame( 2, $q->found_posts );
    683         $this->assertEquals( 2, $q->max_num_pages );
     683        $this->assert( 2, $q->max_num_pages );
    684684    }
    685685
     
    708708
    709709        $this->assertSame( 2, $q->found_posts );
    710         $this->assertEquals( 2, $q->max_num_pages );
     710        $this->assert( 2, $q->max_num_pages );
    711711    }
    712712
  • trunk/tests/phpunit/tests/query/fieldsClause.php

    r54890 r57653  
    6363        $this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
    6464        $this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
    65         $this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
     65        $this->assert( 1, $q->max_num_pages, 'Number of found pages is not one.' );
    6666
    6767        // Test the second query's results match.
     
    8787        $this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
    8888        $this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
    89         $this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
     89        $this->assert( 1, $q->max_num_pages, 'Number of found pages is not one.' );
    9090
    9191        // Test the second query's results match.
     
    111111        $this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
    112112        $this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
    113         $this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
     113        $this->assert( 1, $q->max_num_pages, 'Number of found pages is not one.' );
    114114
    115115        // Test the second query's results match.
     
    146146        $this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
    147147        $this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
    148         $this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
     148        $this->assert( 1, $q->max_num_pages, 'Number of found pages is not one.' );
    149149
    150150        // Test the second query's results match.
     
    174174        $this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
    175175        $this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
    176         $this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
     176        $this->assert( 1, $q->max_num_pages, 'Number of found pages is not one.' );
    177177
    178178        // Test the second query's results match.
     
    205205        $this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
    206206        $this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
    207         $this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
     207        $this->assert( 1, $q->max_num_pages, 'Number of found pages is not one.' );
    208208
    209209        // Test the second query's results match.
Note: See TracChangeset for help on using the changeset viewer.