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

    r55671 r55745  
    457457     */
    458458    public function test_count_query_should_be_cached() {
    459         global $wpdb;
    460 
    461459        register_taxonomy( 'wptests_tax_1', 'post' );
    462460
     
    473471        $this->assertEquals( 2, $count );
    474472
    475         $num_queries = $wpdb->num_queries;
     473        $num_queries = get_num_queries();
    476474
    477475        $query = new WP_Term_Query(
     
    484482        $count = $query->get_terms();
    485483        $this->assertEquals( 2, $count );
    486         $this->assertSame( $num_queries, $wpdb->num_queries );
     484        $this->assertSame( $num_queries, get_num_queries() );
    487485    }
    488486
     
    804802     */
    805803    public function test_terms_pre_query_filter_should_bypass_database_query() {
    806         global $wpdb;
    807 
    808804        add_filter( 'terms_pre_query', array( __CLASS__, 'filter_terms_pre_query' ), 10, 2 );
    809805
    810         $num_queries = $wpdb->num_queries;
     806        $num_queries = get_num_queries();
    811807
    812808        $q       = new WP_Term_Query();
     
    820816
    821817        // Make sure no queries were executed.
    822         $this->assertSame( $num_queries, $wpdb->num_queries );
     818        $this->assertSame( $num_queries, get_num_queries() );
    823819
    824820        // We manually inserted a non-existing term and overrode the results with it.
Note: See TracChangeset for help on using the changeset viewer.