Make WordPress Core


Ignore:
Timestamp:
05/11/2023 10:05:51 AM (2 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/getTerm.php

    r52921 r55745  
    6161
    6262    public function test_passing_term_object_should_skip_database_query_when_filter_property_is_empty() {
    63         global $wpdb;
    64 
    6563        $term = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax' ) );
    6664        clean_term_cache( $term->term_id, 'wptests_tax' );
    6765
    68         $num_queries = $wpdb->num_queries;
     66        $num_queries = get_num_queries();
    6967
    7068        unset( $term->filter );
    7169        $term_a = get_term( $term, 'wptests_tax' );
    7270
    73         $this->assertSame( $num_queries, $wpdb->num_queries );
     71        $this->assertSame( $num_queries, get_num_queries() );
    7472    }
    7573
     
    8381
    8482    public function test_cache_should_be_populated_by_successful_fetch() {
    85         global $wpdb;
    86 
    8783        $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    8884        clean_term_cache( $t, 'wptests_tax' );
     
    9086        // Prime cache.
    9187        $term_a      = get_term( $t, 'wptests_tax' );
    92         $num_queries = $wpdb->num_queries;
     88        $num_queries = get_num_queries();
    9389
    9490        // Second call shouldn't require a database query.
    9591        $term_b = get_term( $t, 'wptests_tax' );
    96         $this->assertSame( $num_queries, $wpdb->num_queries );
     92        $this->assertSame( $num_queries, get_num_queries() );
    9793        $this->assertEquals( $term_a, $term_b );
    9894    }
     
    197193     */
    198194    public function test_shared_term_in_cache_should_be_ignored_when_specifying_a_different_taxonomy() {
    199         global $wpdb;
    200 
    201195        $terms = $this->generate_shared_terms();
    202196
    203197        // Prime cache for 'wptests_tax'.
    204198        get_term( $terms[0]['term_id'], 'wptests_tax' );
    205         $num_queries = $wpdb->num_queries;
     199        $num_queries = get_num_queries();
    206200
    207201        // Database should be hit again.
     
    209203        $num_queries++;
    210204
    211         $this->assertSame( $num_queries, $wpdb->num_queries );
     205        $this->assertSame( $num_queries, get_num_queries() );
    212206        $this->assertInstanceOf( 'WP_Term', $found );
    213207        $this->assertSame( 'wptests_tax_2', $found->taxonomy );
Note: See TracChangeset for help on using the changeset viewer.