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/post/getPages.php

    r50449 r51367  
    1717
    1818        $pages = get_pages();
    19         $this->assertSame( 3, count( $pages ) );
     19        $this->assertCount( 3, $pages );
    2020        $time1 = wp_cache_get( 'last_changed', 'posts' );
    2121        $this->assertNotEmpty( $time1 );
     
    2727        // Again. num_queries and last_changed should remain the same.
    2828        $pages = get_pages();
    29         $this->assertSame( 3, count( $pages ) );
     29        $this->assertCount( 3, $pages );
    3030        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    3131        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    3737        // different args to get_pages(). num_queries should bump by 1.
    3838        $pages = get_pages( array( 'number' => 2 ) );
    39         $this->assertSame( 2, count( $pages ) );
     39        $this->assertCount( 2, $pages );
    4040        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    4141        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     
    4848        // Again. num_queries and last_changed should remain the same.
    4949        $pages = get_pages( array( 'number' => 2 ) );
    50         $this->assertSame( 2, count( $pages ) );
     50        $this->assertCount( 2, $pages );
    5151        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    5252        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    5757        // Do the first query again. The interim queries should not affect it.
    5858        $pages = get_pages();
    59         $this->assertSame( 3, count( $pages ) );
     59        $this->assertCount( 3, $pages );
    6060        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    6161        $this->assertSame( $num_queries, $wpdb->num_queries );
     
    7272        // last_changed bumped so num_queries should increment.
    7373        $pages = get_pages( array( 'number' => 2 ) );
    74         $this->assertSame( 2, count( $pages ) );
     74        $this->assertCount( 2, $pages );
    7575        $this->assertSame( $time2, wp_cache_get( 'last_changed', 'posts' ) );
    7676        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     
    9292        // num_queries should bump after wp_delete_post() bumps last_changed.
    9393        $pages = get_pages();
    94         $this->assertSame( 2, count( $pages ) );
     94        $this->assertCount( 2, $pages );
    9595        $this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'posts' ) );
    9696        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     
    278278            )
    279279        );
    280         $this->assertSame( 3, count( get_pages( array( 'meta_key' => 'some-meta-key' ) ) ) );
     280        $this->assertCount( 3,  get_pages( array( 'meta_key' => 'some-meta-key' ) ) );
    281281    }
    282282
     
    373373        preg_match_all( '#<option#', wp_dropdown_pages( 'echo=0' ), $matches );
    374374
    375         $this->assertSame( 5, count( $matches[0] ) );
     375        $this->assertCount( 5, $matches[0] );
    376376    }
    377377
Note: See TracChangeset for help on using the changeset viewer.