Make WordPress Core

Changeset 61417


Ignore:
Timestamp:
12/29/2025 11:13:54 PM (3 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in wp_count_posts() 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.

Follow-up to [1323/tests], [25554], [27081], [60788].

Props costdev, SergeyBiryukov.
See #64324.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r61173 r61417  
    184184
    185185        $count = wp_count_posts( $post_type, 'readable' );
    186         $this->assertEquals( 1, $count->publish );
     186        $this->assertSame( '1', $count->publish );
    187187
    188188        _unregister_post_type( $post_type );
     
    227227
    228228        $count = wp_count_posts( $post_type, 'readable' );
    229         $this->assertEquals( 5, $count->publish );
     229        $this->assertSame( '5', $count->publish );
    230230        _unregister_post_type( $post_type );
    231231    }
     
    246246
    247247        $count1 = wp_count_posts( $post_type, 'readable' );
    248         $this->assertEquals( 3, $count1->publish );
     248        $this->assertSame( '3', $count1->publish );
    249249
    250250        add_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
    251251        $count2 = wp_count_posts( $post_type, 'readable' );
    252252        remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
    253         $this->assertEquals( 2, $count2->publish );
     253        $this->assertSame( '2', $count2->publish );
    254254    }
    255255
    256256    public function filter_wp_count_posts( $counts ) {
    257         $counts->publish = 2;
     257        $counts->publish = '2';
    258258        return $counts;
    259259    }
     
    277277
    278278        $after_draft_counts = wp_count_posts();
    279         $this->assertEquals( 1, $after_draft_counts->draft );
    280         $this->assertEquals( 2, $after_draft_counts->publish );
     279        $this->assertSame( '1', $after_draft_counts->draft );
     280        $this->assertSame( '2', $after_draft_counts->publish );
    281281        $this->assertNotEquals( $initial_counts->publish, $after_draft_counts->publish );
    282282    }
     
    298298
    299299        $after_trash_counts = wp_count_posts();
    300         $this->assertEquals( 1, $after_trash_counts->trash );
    301         $this->assertEquals( 2, $after_trash_counts->publish );
     300        $this->assertSame( '1', $after_trash_counts->trash );
     301        $this->assertSame( '2', $after_trash_counts->publish );
    302302        $this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish );
    303303    }
Note: See TracChangeset for help on using the changeset viewer.