Make WordPress Core


Ignore:
Timestamp:
05/11/2023 10:05:51 AM (3 years ago)
Author:
spacedmonkey
Message:

Tests: Use the function get_num_queries across all unit tests.

Replace use of $wpdb->num_queries with a function call to get_num_queries. This improves readability and consistency between tests.

Props SergeyBiryukov, peterwilsoncc, spacedmonkey.
See #57841.

File:
1 edited

Legend:

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

    r55169 r55745  
    261261     */
    262262    public function test_should_hit_cache() {
    263         global $wpdb;
    264 
    265263        $page = self::factory()->post->create(
    266264            array(
     
    274272        $this->assertSame( $page, $found->ID );
    275273
    276         $num_queries = $wpdb->num_queries;
    277 
    278         $found = get_page_by_path( 'foo' );
    279         $this->assertSame( $page, $found->ID );
    280         $this->assertSame( $num_queries, $wpdb->num_queries );
     274        $num_queries = get_num_queries();
     275
     276        $found = get_page_by_path( 'foo' );
     277        $this->assertSame( $page, $found->ID );
     278        $this->assertSame( $num_queries, get_num_queries() );
    281279    }
    282280
     
    285283     */
    286284    public function test_bad_path_should_be_cached() {
    287         global $wpdb;
    288 
    289285        // Prime cache.
    290286        $found = get_page_by_path( 'foo' );
    291287        $this->assertNull( $found );
    292288
    293         $num_queries = $wpdb->num_queries;
    294 
    295         $found = get_page_by_path( 'foo' );
    296         $this->assertNull( $found );
    297         $this->assertSame( $num_queries, $wpdb->num_queries );
     289        $num_queries = get_num_queries();
     290
     291        $found = get_page_by_path( 'foo' );
     292        $this->assertNull( $found );
     293        $this->assertSame( $num_queries, get_num_queries() );
    298294    }
    299295
     
    302298     */
    303299    public function test_bad_path_served_from_cache_should_not_fall_back_on_current_post() {
    304         global $wpdb, $post;
     300        global $post;
    305301
    306302        // Fake the global.
     
    311307        $this->assertNull( $found );
    312308
    313         $num_queries = $wpdb->num_queries;
    314 
    315         $found = get_page_by_path( 'foo' );
    316         $this->assertNull( $found );
    317         $this->assertSame( $num_queries, $wpdb->num_queries );
     309        $num_queries = get_num_queries();
     310
     311        $found = get_page_by_path( 'foo' );
     312        $this->assertNull( $found );
     313        $this->assertSame( $num_queries, get_num_queries() );
    318314
    319315        unset( $post );
     
    324320     */
    325321    public function test_cache_should_not_match_post_in_different_post_type_with_same_path() {
    326         global $wpdb;
    327 
    328322        register_post_type( 'wptests_pt' );
    329323
     
    346340        $this->assertSame( $p1, $found->ID );
    347341
    348         $num_queries = $wpdb->num_queries;
     342        $num_queries = get_num_queries();
    349343
    350344        $found = get_page_by_path( 'foo', OBJECT, 'wptests_pt' );
    351345        $this->assertSame( $p2, $found->ID );
    352346        $num_queries++;
    353         $this->assertSame( $num_queries, $wpdb->num_queries );
     347        $this->assertSame( $num_queries, get_num_queries() );
    354348    }
    355349
     
    358352     */
    359353    public function test_cache_should_be_invalidated_when_post_name_is_edited() {
    360         global $wpdb;
    361 
    362354        $page = self::factory()->post->create(
    363355            array(
     
    378370        );
    379371
    380         $num_queries = $wpdb->num_queries;
     372        $num_queries = get_num_queries();
    381373
    382374        $found = get_page_by_path( 'bar' );
    383375        $this->assertSame( $page, $found->ID );
    384376        $num_queries++;
    385         $this->assertSame( $num_queries, $wpdb->num_queries );
     377        $this->assertSame( $num_queries, get_num_queries() );
    386378    }
    387379
Note: See TracChangeset for help on using the changeset viewer.