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/wpGetObjectTerms.php

    r55671 r55745  
    617617     */
    618618    public function test_termmeta_cache_should_be_lazy_loaded_by_default() {
    619         global $wpdb;
    620 
    621619        register_taxonomy( 'wptests_tax', 'post' );
    622620        $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     
    630628        $found = wp_get_object_terms( $p, 'wptests_tax' );
    631629
    632         $num_queries = $wpdb->num_queries;
     630        $num_queries = get_num_queries();
    633631
    634632        foreach ( $terms as $t ) {
     
    636634        }
    637635
    638         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     636        $this->assertSame( $num_queries + 1, get_num_queries() );
    639637    }
    640638
     
    643641     */
    644642    public function test_termmeta_cache_should_not_be_primed_when_update_term_meta_cache_is_false() {
    645         global $wpdb;
    646 
    647643        register_taxonomy( 'wptests_tax', 'post' );
    648644        $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     
    662658        );
    663659
    664         $num_queries = $wpdb->num_queries;
     660        $num_queries = get_num_queries();
    665661
    666662        foreach ( $terms as $t ) {
     
    668664        }
    669665
    670         $this->assertSame( $num_queries + 3, $wpdb->num_queries );
     666        $this->assertSame( $num_queries + 3, get_num_queries() );
    671667    }
    672668
     
    675671     */
    676672    public function test_termmeta_cache_should_be_primed_when_fields_is_all_with_object_id() {
    677         global $wpdb;
    678 
    679673        register_taxonomy( 'wptests_tax', 'post' );
    680674        $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     
    695689        );
    696690
    697         $num_queries = $wpdb->num_queries;
     691        $num_queries = get_num_queries();
    698692
    699693        foreach ( $terms as $t ) {
     
    701695        }
    702696
    703         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     697        $this->assertSame( $num_queries + 1, get_num_queries() );
    704698    }
    705699
     
    708702     */
    709703    public function test_termmeta_cache_should_be_primed_when_fields_is_ids() {
    710         global $wpdb;
    711 
    712704        register_taxonomy( 'wptests_tax', 'post' );
    713705        $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     
    728720        );
    729721
    730         $num_queries = $wpdb->num_queries;
     722        $num_queries = get_num_queries();
    731723
    732724        foreach ( $terms as $t ) {
     
    734726        }
    735727
    736         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     728        $this->assertSame( $num_queries + 1, get_num_queries() );
    737729    }
    738730
     
    817809     */
    818810    public function test_should_prime_cache_for_found_terms() {
    819         global $wpdb;
    820 
    821811        register_taxonomy( 'wptests_tax', 'post' );
    822812        $p = self::factory()->post->create();
     
    832822        );
    833823
    834         $num_queries = $wpdb->num_queries;
     824        $num_queries = get_num_queries();
    835825        $term        = get_term( $t );
    836         $this->assertSame( $num_queries, $wpdb->num_queries );
     826        $this->assertSame( $num_queries, get_num_queries() );
    837827    }
    838828
     
    866856     */
    867857    public function test_term_cache_should_be_primed_for_all_taxonomies() {
    868         global $wpdb;
    869 
    870858        register_taxonomy( 'wptests_tax1', 'post' );
    871859        register_taxonomy( 'wptests_tax2', 'post' );
     
    889877        $this->assertSameSets( array( $t1, $t2 ), wp_list_pluck( $found, 'term_id' ) );
    890878
    891         $num_queries = $wpdb->num_queries;
     879        $num_queries = get_num_queries();
    892880        $term1       = get_term( $t1 );
    893881        $term2       = get_term( $t2 );
    894         $this->assertSame( $num_queries, $wpdb->num_queries );
     882        $this->assertSame( $num_queries, get_num_queries() );
    895883    }
    896884
Note: See TracChangeset for help on using the changeset viewer.