Make WordPress Core


Ignore:
Timestamp:
07/07/2021 10:32:56 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertSame( [number], count( ... ) ) with assertCount() to use native PHPUnit functionality.

Follow-up to [51335], [51337].

See #53363.

File:
1 edited

Legend:

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

    r51331 r51367  
    102102
    103103        $tt = wp_add_object_terms( $posts[0], $tags[1], 'post_tag' );
    104         $this->assertSame( 1, count( $tt ) );
     104        $this->assertCount( 1, $tt );
    105105        $this->assertSame( array( $tags[1] ), wp_get_object_terms( $posts[0], 'post_tag', array( 'fields' => 'ids' ) ) );
    106106
    107107        $three_tags = array( $tags[0], $tags[1], $tags[2] );
    108108        $tt         = wp_add_object_terms( $posts[1], $three_tags, 'post_tag' );
    109         $this->assertSame( 3, count( $tt ) );
     109        $this->assertCount( 3, $tt );
    110110        $this->assertSame( $three_tags, wp_get_object_terms( $posts[1], 'post_tag', array( 'fields' => 'ids' ) ) );
    111111
     
    114114        $this->assertInstanceOf( 'WP_Error', wp_remove_object_terms( $posts[0], $tags[1], 'non_existing_taxonomy' ) );
    115115        $this->assertTrue( wp_remove_object_terms( $posts[1], $three_tags, 'post_tag' ) );
    116         $this->assertSame( 0, count( wp_get_object_terms( $posts[1], 'post_tag' ) ) );
     116        $this->assertCount( 0, wp_get_object_terms( $posts[1], 'post_tag' ) );
    117117
    118118        foreach ( $tags as $term_id ) {
     
    178178
    179179        $this->assertIsArray( $post->post_category );
    180         $this->assertSame( 1, count( $post->post_category ) );
     180        $this->assertCount( 1, $post->post_category );
    181181        $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] );
    182182
     
    186186
    187187        wp_set_post_categories( $post_id, array( $term1['term_id'], $term2['term_id'] ) );
    188         $this->assertSame( 2, count( $post->post_category ) );
     188        $this->assertCount( 2, $post->post_category );
    189189        $this->assertSame( array( $term2['term_id'], $term1['term_id'] ), $post->post_category );
    190190
     
    201201
    202202        wp_set_post_categories( $post_id, array(), true );
    203         $this->assertSame( 1, count( $post->post_category ) );
     203        $this->assertCount( 1, $post->post_category );
    204204        $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] );
    205205
    206206        wp_set_post_categories( $post_id, array() );
    207         $this->assertSame( 1, count( $post->post_category ) );
     207        $this->assertCount( 1, $post->post_category );
    208208        $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] );
    209209    }
Note: See TracChangeset for help on using the changeset viewer.