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/term/getTermBy.php

    r54090 r55745  
    112112     */
    113113    public function test_should_prime_term_cache() {
    114         global $wpdb;
    115 
    116114        register_taxonomy( 'wptests_tax', 'post' );
    117115        $t = self::factory()->term->create(
     
    124122        clean_term_cache( $t, 'wptests_tax' );
    125123
    126         $num_queries = $wpdb->num_queries;
     124        $num_queries = get_num_queries();
    127125        $found       = get_term_by( 'slug', 'foo', 'wptests_tax' );
    128126        $num_queries = $num_queries + 2;
     
    130128        $this->assertInstanceOf( 'WP_Term', $found );
    131129        $this->assertSame( $t, $found->term_id );
    132         $this->assertSame( $num_queries, $wpdb->num_queries );
     130        $this->assertSame( $num_queries, get_num_queries() );
    133131
    134132        // Calls to `get_term()` should now hit cache.
    135133        $found2 = get_term( $t );
    136134        $this->assertSame( $t, $found->term_id );
    137         $this->assertSame( $num_queries, $wpdb->num_queries );
     135        $this->assertSame( $num_queries, get_num_queries() );
    138136    }
    139137
Note: See TracChangeset for help on using the changeset viewer.