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/multisite/wpSiteQuery.php

    r53097 r55745  
    780780                 */
    781781                public function test_wp_site_query_cache_with_different_fields_no_count() {
    782                         global $wpdb;
    783782                        $q                 = new WP_Site_Query();
    784783                        $query_1           = $q->query(
     
    790789                                )
    791790                        );
    792                         $number_of_queries = $wpdb->num_queries;
     791                        $number_of_queries = get_num_queries();
    793792
    794793                        $query_2 = $q->query(
     
    801800                        );
    802801
    803                         $this->assertSame( $number_of_queries, $wpdb->num_queries );
     802                        $this->assertSame( $number_of_queries, get_num_queries() );
    804803                }
    805804
     
    808807                 */
    809808                public function test_wp_site_query_cache_with_different_fields_active_count() {
    810                         global $wpdb;
    811809                        $q = new WP_Site_Query();
    812810
     
    820818                                )
    821819                        );
    822                         $number_of_queries = $wpdb->num_queries;
     820                        $number_of_queries = get_num_queries();
    823821
    824822                        $query_2 = $q->query(
     
    831829                                )
    832830                        );
    833                         $this->assertSame( $number_of_queries, $wpdb->num_queries );
     831                        $this->assertSame( $number_of_queries, get_num_queries() );
    834832                }
    835833
     
    838836                 */
    839837                public function test_wp_site_query_cache_with_same_fields_different_count() {
    840                         global $wpdb;
    841838                        $q = new WP_Site_Query();
    842839
     
    861858                                )
    862859                        );
    863                         $this->assertSame( $number_of_queries + 1, $wpdb->num_queries );
     860                        $this->assertSame( $number_of_queries + 1, get_num_queries() );
    864861                }
    865862
     
    11201117                 */
    11211118                public function test_sites_pre_query_filter_should_bypass_database_query() {
    1122                         global $wpdb;
    1123 
    11241119                        add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
    11251120
    1126                         $num_queries = $wpdb->num_queries;
     1121                        $num_queries = get_num_queries();
    11271122
    11281123                        $q       = new WP_Site_Query();
     
    11321127
    11331128                        // Make sure no queries were executed.
    1134                         $this->assertSame( $num_queries, $wpdb->num_queries );
     1129                        $this->assertSame( $num_queries, get_num_queries() );
    11351130
    11361131                        // We manually inserted a non-existing site and overrode the results with it.
Note: See TracChangeset for help on using the changeset viewer.