Make WordPress Core

Changeset 55745


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

Location:
trunk
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/package-lock.json

    r55737 r55745  
    1195511955            "version": "1.1.0",
    1195611956            "resolved": "https://registry.npmjs.org/from2-string/-/from2-string-1.1.0.tgz",
    11957             "integrity": "sha512-m8vCh+KnXXXBtfF2VUbiYlQ+nczLcntB0BrtNgpmLkHylhObe9WF1b2LZjBBzrZzA6P4mkEla6ZYQoOUTG8cYA==",
     11957            "integrity": "sha1-GCgrJ9CKJnyzAwzSuLSw8hKvdSo=",
    1195811958            "requires": {
    1195911959                "from2": "^2.0.3"
     
    2111321113            "version": "1.1.6",
    2111421114            "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-1.1.6.tgz",
    21115             "integrity": "sha512-7rrONfyLkDEc7OJ5QBkqa4KI4EBhCd340xRuIUPGCfu13znS+vx+VDdrT9ODAJHlXm7w4lbxN3DRjyv58EuzDg=="
     21115            "integrity": "sha1-zQTv9G9clcOn0EVZHXm14+AfEtc="
    2111621116        },
    2111721117        "prompts": {
     
    2325223252            "version": "1.0.0",
    2325323253            "resolved": "https://registry.npmjs.org/stream-from-promise/-/stream-from-promise-1.0.0.tgz",
    23254             "integrity": "sha512-j84KLkudt+gr8KJ21RB02btPLx61uGbrLnewsWz6QKmsz8/c4ZFqXw6mJh5+G4oRN7DgDxdbjPxnpySpg1mUig=="
     23254            "integrity": "sha1-djaH9913fkyJT2QIMz/Gs/yKYbs="
    2325523255        },
    2325623256        "stream-to-string": {
     
    2452024520            "version": "2.0.2",
    2452124521            "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz",
    24522             "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg=="
     24522            "integrity": "sha1-riF2gXXRVZ1IvvNUILL0li8JwzA="
    2452324523        },
    2452424524        "totalist": {
  • trunk/tests/phpunit/tests/bookmark/getBookmarks.php

    r51454 r55745  
    66class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
    77    public function test_should_hit_cache() {
    8         global $wpdb;
    9 
    108        $bookmarks = self::factory()->bookmark->create_many( 2 );
    119
     
    1614        );
    1715
    18         $num_queries = $wpdb->num_queries;
     16        $num_queries = get_num_queries();
    1917
    2018        $found2 = get_bookmarks(
     
    2523
    2624        $this->assertSameSets( $found1, $found2 );
    27         $this->assertSame( $num_queries, $wpdb->num_queries );
     25        $this->assertSame( $num_queries, get_num_queries() );
    2826    }
    2927
    3028    public function test_adding_bookmark_should_bust_get_bookmarks_cache() {
    31         global $wpdb;
    32 
    3329        $bookmarks = self::factory()->bookmark->create_many( 2 );
    3430
     
    4036        );
    4137
    42         $num_queries = $wpdb->num_queries;
     38        $num_queries = get_num_queries();
    4339
    4440        $bookmarks[] = wp_insert_link(
     
    5652
    5753        $this->assertEqualSets( $bookmarks, wp_list_pluck( $found2, 'link_id' ) );
    58         $this->assertGreaterThan( $num_queries, $wpdb->num_queries );
     54        $this->assertGreaterThan( $num_queries, get_num_queries() );
    5955    }
    6056
     
    6359     */
    6460    public function test_orderby_rand_should_not_be_cached() {
    65         global $wpdb;
    66 
    6761        $bookmarks = self::factory()->bookmark->create_many( 2 );
    6862
     
    7367        );
    7468
    75         $num_queries = $wpdb->num_queries;
     69        $num_queries = get_num_queries();
    7670
    7771        $found2 = get_bookmarks(
     
    8377        // Equal sets != same order.
    8478        $this->assertEqualSets( $found1, $found2 );
    85         $this->assertGreaterThan( $num_queries, $wpdb->num_queries );
     79        $this->assertGreaterThan( $num_queries, get_num_queries() );
    8680    }
    8781
  • trunk/tests/phpunit/tests/comment/getPageOfComment.php

    r53863 r55745  
    101101     */
    102102    public function test_subsequent_calls_should_hit_cache() {
    103         global $wpdb;
    104 
    105103        $p = self::factory()->post->create();
    106104        $c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) );
     
    109107        $page_1 = get_page_of_comment( $c, array( 'per_page' => 3 ) );
    110108
    111         $num_queries = $wpdb->num_queries;
     109        $num_queries = get_num_queries();
    112110        $page_2      = get_page_of_comment( $c, array( 'per_page' => 3 ) );
    113111
    114112        $this->assertSame( $page_1, $page_2 );
    115         $this->assertSame( $num_queries, $wpdb->num_queries );
     113        $this->assertSame( $num_queries, get_num_queries() );
    116114    }
    117115
     
    120118     */
    121119    public function test_cache_hits_should_be_sensitive_to_comment_type() {
    122         global $wpdb;
    123 
    124120        $p       = self::factory()->post->create();
    125121        $comment = self::factory()->comment->create(
     
    152148        $this->assertSame( 2, $page_trackbacks );
    153149
    154         $num_queries   = $wpdb->num_queries;
     150        $num_queries   = get_num_queries();
    155151        $page_comments = get_page_of_comment(
    156152            $comment,
     
    162158        $this->assertSame( 1, $page_comments );
    163159
    164         $this->assertNotEquals( $num_queries, $wpdb->num_queries );
     160        $this->assertNotEquals( $num_queries, get_num_queries() );
    165161    }
    166162
  • trunk/tests/phpunit/tests/comment/metaCache.php

    r54704 r55745  
    1313     */
    1414    public function test_update_comment_meta_cache_should_default_to_true() {
    15         global $wpdb;
    16 
    1715        $p           = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    1816        $comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
     
    3129        );
    3230
    33         $num_queries = $wpdb->num_queries;
     31        $num_queries = get_num_queries();
    3432        foreach ( $comment_ids as $cid ) {
    3533            get_comment_meta( $cid, 'foo', 'bar' );
    3634        }
    3735
    38         $this->assertSame( $num_queries, $wpdb->num_queries );
     36        $this->assertSame( $num_queries, get_num_queries() );
    3937    }
    4038
     
    4543     */
    4644    public function test_update_comment_meta_cache_true() {
    47         global $wpdb;
    48 
    4945        $p           = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    5046        $comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
     
    6460        );
    6561
    66         $num_queries = $wpdb->num_queries;
     62        $num_queries = get_num_queries();
    6763        foreach ( $comment_ids as $cid ) {
    6864            get_comment_meta( $cid, 'foo', 'bar' );
    6965        }
    7066
    71         $this->assertSame( $num_queries, $wpdb->num_queries );
     67        $this->assertSame( $num_queries, get_num_queries() );
    7268    }
    7369
     
    7874     */
    7975    public function test_update_comment_meta_cache_false() {
    80         global $wpdb;
    81 
    8276        $p           = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    8377        $comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
     
    9488        );
    9589
    96         $num_queries = $wpdb->num_queries;
     90        $num_queries = get_num_queries();
    9791        foreach ( $comment_ids as $cid ) {
    9892            get_comment_meta( $cid, 'foo', 'bar' );
    9993        }
    10094
    101         $this->assertSame( $num_queries + 3, $wpdb->num_queries );
     95        $this->assertSame( $num_queries + 3, get_num_queries() );
    10296    }
    10397
     
    108102     */
    109103    public function test_comment_meta_should_be_lazy_loaded_for_all_comments_in_comments_template() {
    110         global $wpdb;
    111 
    112104        $p           = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    113105        $comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
     
    127119
    128120                // First request will hit the database.
    129                 $num_queries = $wpdb->num_queries;
     121                $num_queries = get_num_queries();
    130122                get_comment_meta( $comment_ids[0], 'sauce' );
    131                 $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     123                $this->assertSame( $num_queries + 1, get_num_queries() );
    132124
    133125                // Second and third requests should be in cache.
    134126                get_comment_meta( $comment_ids[1], 'sauce' );
    135127                get_comment_meta( $comment_ids[2], 'sauce' );
    136                 $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     128                $this->assertSame( $num_queries + 1, get_num_queries() );
    137129            }
    138130        }
     
    145137     */
    146138    public function test_comment_meta_should_be_lazy_loaded_in_comment_feed_queries() {
    147         global $wpdb;
    148 
    149139        $posts = self::factory()->post->create_many( 2, array( 'post_status' => 'publish' ) );
    150140
     
    174164
    175165        // First comment will cause the cache to be primed.
    176         $num_queries = $wpdb->num_queries;
     166        $num_queries = get_num_queries();
    177167        $this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) );
    178168        $num_queries++;
    179         $this->assertSame( $num_queries, $wpdb->num_queries );
     169        $this->assertSame( $num_queries, get_num_queries() );
    180170
    181171        // Second comment from the results should not cause more queries.
    182172        $this->assertSame( 'bar', get_comment_meta( $comments[1], 'foo', 'bar' ) );
    183         $this->assertSame( $num_queries, $wpdb->num_queries );
     173        $this->assertSame( $num_queries, get_num_queries() );
    184174
    185175        // A comment from outside the results will not be primed.
    186176        $this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) );
    187177        $num_queries++;
    188         $this->assertSame( $num_queries, $wpdb->num_queries );
     178        $this->assertSame( $num_queries, get_num_queries() );
    189179    }
    190180
     
    195185     */
    196186    public function test_comment_meta_should_be_lazy_loaded_in_single_post_comment_feed_queries() {
    197         global $wpdb;
    198 
    199187        $posts = self::factory()->post->create_many( 2, array( 'post_status' => 'publish' ) );
    200188
     
    225213
    226214        // First comment will cause the cache to be primed.
    227         $num_queries = $wpdb->num_queries;
     215        $num_queries = get_num_queries();
    228216        $this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) );
    229217        $num_queries++;
    230         $this->assertSame( $num_queries, $wpdb->num_queries );
     218        $this->assertSame( $num_queries, get_num_queries() );
    231219
    232220        // Second comment from the results should not cause more queries.
    233221        $this->assertSame( 'bar', get_comment_meta( $comments[1], 'foo', 'bar' ) );
    234         $this->assertSame( $num_queries, $wpdb->num_queries );
     222        $this->assertSame( $num_queries, get_num_queries() );
    235223
    236224        // A comment from outside the results will not be primed.
    237225        $this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) );
    238226        $num_queries++;
    239         $this->assertSame( $num_queries, $wpdb->num_queries );
     227        $this->assertSame( $num_queries, get_num_queries() );
    240228    }
    241229
  • trunk/tests/phpunit/tests/comment/query.php

    r54704 r55745  
    35893589     */
    35903590    public function test_comment_cache_key_should_ignore_custom_params() {
    3591         global $wpdb;
    3592 
    35933591        $p = self::factory()->post->create();
    35943592        $c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) );
     
    36023600        );
    36033601
    3604         $num_queries = $wpdb->num_queries;
     3602        $num_queries = get_num_queries();
    36053603
    36063604        $q2 = new WP_Comment_Query();
     
    36133611        );
    36143612
    3615         $this->assertSame( $num_queries, $wpdb->num_queries );
     3613        $this->assertSame( $num_queries, get_num_queries() );
    36163614    }
    36173615
     
    36303628        );
    36313629
    3632         $num_queries = $wpdb->num_queries;
     3630        $num_queries = get_num_queries();
    36333631
    36343632        $q2 = new WP_Comment_Query(
     
    36383636        );
    36393637
    3640         $this->assertNotEquals( $num_queries, $wpdb->num_queries );
     3638        $this->assertNotEquals( $num_queries, get_num_queries() );
    36413639    }
    36423640
     
    36553653        );
    36563654
    3657         $num_queries = $wpdb->num_queries;
     3655        $num_queries = get_num_queries();
    36583656
    36593657        $q2 = new WP_Comment_Query(
     
    36633661        );
    36643662
    3665         $this->assertNotEquals( $num_queries, $wpdb->num_queries );
     3663        $this->assertNotEquals( $num_queries, get_num_queries() );
    36663664    }
    36673665
     
    44284426        $q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' );
    44294427
    4430         $num_queries = $wpdb->num_queries;
     4428        $num_queries = get_num_queries();
    44314429        $q2          = new WP_Comment_Query(
    44324430            array(
     
    44384436
    44394437        $this->assertSameSets( $q1_ids, $q2_ids );
    4440         $this->assertSame( $num_queries, $wpdb->num_queries );
     4438        $this->assertSame( $num_queries, get_num_queries() );
    44414439    }
    44424440
     
    45914589        );
    45924590
    4593         $num_queries = $wpdb->num_queries;
     4591        $num_queries = get_num_queries();
    45944592        $this->assertTrue( isset( $q->comments[0]->post_name ) );
    4595         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     4593        $this->assertSame( $num_queries + 1, get_num_queries() );
    45964594    }
    45974595
     
    46144612        );
    46154613
    4616         $num_queries = $wpdb->num_queries;
     4614        $num_queries = get_num_queries();
    46174615        $this->assertTrue( isset( $q->comments[0]->post_name ) );
    4618         $this->assertSame( $num_queries, $wpdb->num_queries );
     4616        $this->assertSame( $num_queries, get_num_queries() );
    46194617    }
    46204618
     
    46304628        clean_comment_cache( $comments );
    46314629
    4632         $num_queries = $wpdb->num_queries;
     4630        $num_queries = get_num_queries();
    46334631        $q           = new WP_Comment_Query(
    46344632            array(
     
    46464644        $this->assertEqualSets( $comments, $found );
    46474645
    4648         $this->assertSame( $num_queries, $wpdb->num_queries );
     4646        $this->assertSame( $num_queries, get_num_queries() );
    46494647    }
    46504648
     
    46934691        );
    46944692
    4695         $num_queries = $wpdb->num_queries;
     4693        $num_queries = get_num_queries();
    46964694
    46974695        $q2 = new WP_Comment_Query(
     
    47024700        );
    47034701
    4704         $this->assertSame( $num_queries, $wpdb->num_queries );
     4702        $this->assertSame( $num_queries, get_num_queries() );
    47054703    }
    47064704
     
    47254723        );
    47264724
    4727         $num_queries = $wpdb->num_queries;
     4725        $num_queries = get_num_queries();
    47284726
    47294727        $q = new WP_Comment_Query(
     
    47344732        );
    47354733
    4736         $this->assertSame( $num_queries, $wpdb->num_queries );
     4734        $this->assertSame( $num_queries, get_num_queries() );
    47374735        $this->assertSameSets( array( $c ), $q->comments );
    47384736    }
     
    47674765        );
    47684766
    4769         $num_queries = $wpdb->num_queries;
     4767        $num_queries = get_num_queries();
    47704768
    47714769        $q = new WP_Comment_Query(
     
    47774775
    47784776        $num_queries++;
    4779         $this->assertSame( $num_queries, $wpdb->num_queries );
     4777        $this->assertSame( $num_queries, get_num_queries() );
    47804778        $this->assertSameSets( array( $c ), $q->comments );
    47814779    }
     
    48034801        wp_delete_comment( $c );
    48044802
    4805         $num_queries = $wpdb->num_queries;
     4803        $num_queries = get_num_queries();
    48064804
    48074805        $q = new WP_Comment_Query(
     
    48134811
    48144812        $num_queries++;
    4815         $this->assertSame( $num_queries, $wpdb->num_queries );
     4813        $this->assertSame( $num_queries, get_num_queries() );
    48164814        $this->assertSameSets( array(), $q->comments );
    48174815    }
     
    48394837        wp_trash_comment( $c );
    48404838
    4841         $num_queries = $wpdb->num_queries;
     4839        $num_queries = get_num_queries();
    48424840
    48434841        $q = new WP_Comment_Query(
     
    48494847
    48504848        $num_queries++;
    4851         $this->assertSame( $num_queries, $wpdb->num_queries );
     4849        $this->assertSame( $num_queries, get_num_queries() );
    48524850        $this->assertSameSets( array(), $q->comments );
    48534851    }
     
    48774875        wp_untrash_comment( $c );
    48784876
    4879         $num_queries = $wpdb->num_queries;
     4877        $num_queries = get_num_queries();
    48804878
    48814879        $q = new WP_Comment_Query(
     
    48874885
    48884886        $num_queries++;
    4889         $this->assertSame( $num_queries, $wpdb->num_queries );
     4887        $this->assertSame( $num_queries, get_num_queries() );
    48904888        $this->assertSameSets( array( $c ), $q->comments );
    48914889    }
     
    49134911        wp_spam_comment( $c );
    49144912
    4915         $num_queries = $wpdb->num_queries;
     4913        $num_queries = get_num_queries();
    49164914
    49174915        $q = new WP_Comment_Query(
     
    49234921
    49244922        $num_queries++;
    4925         $this->assertSame( $num_queries, $wpdb->num_queries );
     4923        $this->assertSame( $num_queries, get_num_queries() );
    49264924        $this->assertSameSets( array(), $q->comments );
    49274925    }
     
    49514949        wp_unspam_comment( $c );
    49524950
    4953         $num_queries = $wpdb->num_queries;
     4951        $num_queries = get_num_queries();
    49544952
    49554953        $q = new WP_Comment_Query(
     
    49614959
    49624960        $num_queries++;
    4963         $this->assertSame( $num_queries, $wpdb->num_queries );
     4961        $this->assertSame( $num_queries, get_num_queries() );
    49644962        $this->assertSameSets( array( $c ), $q->comments );
    49654963    }
     
    49834981        );
    49844982
    4985         $number_of_queries = $wpdb->num_queries;
     4983        $number_of_queries = get_num_queries();
    49864984
    49874985        $query_2 = $q->query(
     
    49934991            )
    49944992        );
    4995         $this->assertSame( $number_of_queries + 1, $wpdb->num_queries );
     4993        $this->assertSame( $number_of_queries + 1, get_num_queries() );
    49964994    }
    49974995
     
    50145012            )
    50155013        );
    5016         $number_of_queries = $wpdb->num_queries;
     5014        $number_of_queries = get_num_queries();
    50175015
    50185016        $query_2 = $q->query(
     
    50245022            )
    50255023        );
    5026         $this->assertSame( $number_of_queries, $wpdb->num_queries );
     5024        $this->assertSame( $number_of_queries, get_num_queries() );
    50275025    }
    50285026
     
    50445042            )
    50455043        );
    5046         $number_of_queries = $wpdb->num_queries;
     5044        $number_of_queries = get_num_queries();
    50475045
    50485046        $query_2 = $q->query(
     
    50545052        );
    50555053
    5056         $this->assertSame( $number_of_queries, $wpdb->num_queries );
     5054        $this->assertSame( $number_of_queries, get_num_queries() );
    50575055    }
    50585056
     
    52205218        add_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query' ), 10, 2 );
    52215219
    5222         $num_queries = $wpdb->num_queries;
     5220        $num_queries = get_num_queries();
    52235221
    52245222        $q       = new WP_Comment_Query();
     
    52285226
    52295227        // Make sure no queries were executed.
    5230         $this->assertSame( $num_queries, $wpdb->num_queries );
     5228        $this->assertSame( $num_queries, get_num_queries() );
    52315229
    52325230        // We manually inserted a non-existing site and overrode the results with it.
  • trunk/tests/phpunit/tests/comment/wpUpdateCommentCountNow.php

    r54704 r55745  
    1515
    1616    public function test_regular_post_updates_comment_count() {
    17         global $wpdb;
    18 
    1917        $post_id = self::factory()->post->create();
    2018
     
    2220        $this->assertSame( '1', get_comments_number( $post_id ) );
    2321
    24         $num_queries = $wpdb->num_queries;
     22        $num_queries = get_num_queries();
    2523        $this->assertTrue( wp_update_comment_count_now( $post_id ) );
    26         $this->assertSame( $num_queries + 2, $wpdb->num_queries );
     24        $this->assertSame( $num_queries + 2, get_num_queries() );
    2725
    2826        $this->assertSame( '1', get_comments_number( $post_id ) );
     
    3937        $this->assertSame( '100', get_comments_number( $post_id ) );
    4038
    41         $num_queries = $wpdb->num_queries;
     39        $num_queries = get_num_queries();
    4240        $this->assertTrue( wp_update_comment_count_now( $post_id ) );
    4341        // Only one query is made instead of two.
    44         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     42        $this->assertSame( $num_queries + 1, get_num_queries() );
    4543
    4644        $this->assertSame( '100', get_comments_number( $post_id ) );
  • trunk/tests/phpunit/tests/customize/manager.php

    r55039 r55745  
    272272     */
    273273    public function test_fresh_site_flag_clearing() {
    274         global $wp_customize, $wpdb;
     274        global $wp_customize;
    275275
    276276        // Make sure fresh site flag is cleared when publishing a changeset.
     
    284284
    285285        // Make sure no DB write is done when publishing and a site is already non-fresh.
    286         $query_count = $wpdb->num_queries;
     286        $query_count = get_num_queries();
    287287        do_action( 'customize_save_after', $wp_customize );
    288         $this->assertSame( $query_count, $wpdb->num_queries );
     288        $this->assertSame( $query_count, get_num_queries() );
    289289    }
    290290
  • trunk/tests/phpunit/tests/general/wpGetArchives.php

    r52010 r55745  
    1717     */
    1818    public function test_get_archives_cache() {
    19         global $wpdb;
    20 
    2119        self::factory()->post->create_many( 3, array( 'post_type' => 'post' ) );
    2220        wp_cache_delete( 'last_changed', 'posts' );
    2321        $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
    2422
    25         $num_queries = $wpdb->num_queries;
     23        $num_queries = get_num_queries();
    2624
    2725        // Cache is not primed, expect 1 query.
     
    3533        $time1 = wp_cache_get( 'last_changed', 'posts' );
    3634        $this->assertNotEmpty( $time1 );
    37         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     35        $this->assertSame( $num_queries + 1, get_num_queries() );
    3836
    39         $num_queries = $wpdb->num_queries;
     37        $num_queries = get_num_queries();
    4038
    4139        // Cache is primed, expect no queries.
     
    4846        $this->assertIsString( $result );
    4947        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    50         $this->assertSame( $num_queries, $wpdb->num_queries );
     48        $this->assertSame( $num_queries, get_num_queries() );
    5149
    5250        // Change args, resulting in a different query string. Cache is not primed, expect 1 query.
     
    6058        $this->assertIsString( $result );
    6159        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    62         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     60        $this->assertSame( $num_queries + 1, get_num_queries() );
    6361
    64         $num_queries = $wpdb->num_queries;
     62        $num_queries = get_num_queries();
    6563
    6664        // Cache is primed, expect no queries.
     
    7472        $this->assertIsString( $result );
    7573        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    76         $this->assertSame( $num_queries, $wpdb->num_queries );
     74        $this->assertSame( $num_queries, get_num_queries() );
    7775
    78         $num_queries = $wpdb->num_queries;
     76        $num_queries = get_num_queries();
    7977
    8078        // Change type. Cache is not primed, expect 1 query.
     
    8785        $this->assertIsString( $result );
    8886        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    89         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     87        $this->assertSame( $num_queries + 1, get_num_queries() );
    9088
    91         $num_queries = $wpdb->num_queries;
     89        $num_queries = get_num_queries();
    9290
    9391        // Cache is primed, expect no queries.
     
    10098        $this->assertIsString( $result );
    10199        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    102         $this->assertSame( $num_queries, $wpdb->num_queries );
     100        $this->assertSame( $num_queries, get_num_queries() );
    103101
    104102        // Change type. Cache is not primed, expect 1 query.
     
    111109        $this->assertIsString( $result );
    112110        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    113         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     111        $this->assertSame( $num_queries + 1, get_num_queries() );
    114112
    115         $num_queries = $wpdb->num_queries;
     113        $num_queries = get_num_queries();
    116114
    117115        // Cache is primed, expect no queries.
     
    124122        $this->assertIsString( $result );
    125123        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    126         $this->assertSame( $num_queries, $wpdb->num_queries );
     124        $this->assertSame( $num_queries, get_num_queries() );
    127125
    128126        // Change type. Cache is not primed, expect 1 query.
     
    135133        $this->assertIsString( $result );
    136134        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    137         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     135        $this->assertSame( $num_queries + 1, get_num_queries() );
    138136
    139         $num_queries = $wpdb->num_queries;
     137        $num_queries = get_num_queries();
    140138
    141139        // Cache is primed, expect no queries.
     
    148146        $this->assertIsString( $result );
    149147        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    150         $this->assertSame( $num_queries, $wpdb->num_queries );
     148        $this->assertSame( $num_queries, get_num_queries() );
    151149
    152150        // Change type. Cache is not primed, expect 1 query.
     
    159157        $this->assertIsString( $result );
    160158        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    161         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     159        $this->assertSame( $num_queries + 1, get_num_queries() );
    162160
    163         $num_queries = $wpdb->num_queries;
     161        $num_queries = get_num_queries();
    164162
    165163        // Cache is primed, expect no queries.
     
    172170        $this->assertIsString( $result );
    173171        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    174         $this->assertSame( $num_queries, $wpdb->num_queries );
     172        $this->assertSame( $num_queries, get_num_queries() );
    175173    }
    176174}
  • trunk/tests/phpunit/tests/multisite/network.php

    r54637 r55745  
    591591         */
    592592        public function test_get_network_not_found_cache() {
    593             global $wpdb;
    594 
    595593            $new_network_id = $this->_get_next_network_id();
    596594            $this->assertNull( get_network( $new_network_id ) );
    597595
    598             $num_queries = $wpdb->num_queries;
     596            $num_queries = get_num_queries();
    599597            $this->assertNull( get_network( $new_network_id ) );
    600             $this->assertSame( $num_queries, $wpdb->num_queries );
     598            $this->assertSame( $num_queries, get_num_queries() );
    601599        }
    602600
  • trunk/tests/phpunit/tests/multisite/site.php

    r55043 r55745  
    21712171         */
    21722172        public function test_get_site_not_found_cache() {
    2173             global $wpdb;
    2174 
    21752173            $new_site_id = $this->_get_next_site_id();
    21762174            $this->assertNull( get_site( $new_site_id ) );
    21772175
    2178             $num_queries = $wpdb->num_queries;
     2176            $num_queries = get_num_queries();
    21792177            $this->assertNull( get_site( $new_site_id ) );
    2180             $this->assertSame( $num_queries, $wpdb->num_queries );
     2178            $this->assertSame( $num_queries, get_num_queries() );
    21812179        }
    21822180
  • trunk/tests/phpunit/tests/multisite/siteMeta.php

    r51860 r55745  
    221221
    222222        public function test_update_site_meta_cache() {
    223             global $wpdb;
    224 
    225223            if ( ! is_site_meta_supported() ) {
    226224                $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
     
    230228            update_sitemeta_cache( array( self::$site_id ) );
    231229
    232             $num_queries = $wpdb->num_queries;
     230            $num_queries = get_num_queries();
    233231            get_site_meta( self::$site_id, 'foo', true );
    234             $this->assertSame( $num_queries, $wpdb->num_queries );
     232            $this->assertSame( $num_queries, get_num_queries() );
    235233        }
    236234
    237235        public function test_query_update_site_meta_cache_true() {
    238             global $wpdb;
    239 
    240236            if ( ! is_site_meta_supported() ) {
    241237                $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
     
    251247            );
    252248
    253             $num_queries = $wpdb->num_queries;
     249            $num_queries = get_num_queries();
    254250            get_site_meta( self::$site_id, 'foo', true );
    255             $this->assertSame( $num_queries, $wpdb->num_queries );
     251            $this->assertSame( $num_queries, get_num_queries() );
    256252        }
    257253
    258254        public function test_query_update_site_meta_cache_false() {
    259             global $wpdb;
    260 
    261255            if ( ! is_site_meta_supported() ) {
    262256                $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
     
    272266            );
    273267
    274             $num_queries = $wpdb->num_queries;
     268            $num_queries = get_num_queries();
    275269            get_site_meta( self::$site_id, 'foo', true );
    276             $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     270            $this->assertSame( $num_queries + 1, get_num_queries() );
    277271        }
    278272
  • trunk/tests/phpunit/tests/multisite/wpNetworkQuery.php

    r53098 r55745  
    429429         */
    430430        public function test_wp_network_query_cache_with_different_fields_no_count() {
    431             global $wpdb;
    432 
    433431            $q                 = new WP_Network_Query();
    434432            $query_1           = $q->query(
     
    439437                )
    440438            );
    441             $number_of_queries = $wpdb->num_queries;
     439            $number_of_queries = get_num_queries();
    442440
    443441            $query_2 = $q->query(
     
    449447            );
    450448
    451             $this->assertSame( $number_of_queries, $wpdb->num_queries );
     449            $this->assertSame( $number_of_queries, get_num_queries() );
    452450        }
    453451
     
    456454         */
    457455        public function test_wp_network_query_cache_with_different_fields_active_count() {
    458             global $wpdb;
    459 
    460456            $q = new WP_Network_Query();
    461457
     
    468464                )
    469465            );
    470             $number_of_queries = $wpdb->num_queries;
     466            $number_of_queries = get_num_queries();
    471467
    472468            $query_2 = $q->query(
     
    478474                )
    479475            );
    480             $this->assertSame( $number_of_queries, $wpdb->num_queries );
     476            $this->assertSame( $number_of_queries, get_num_queries() );
    481477        }
    482478
     
    485481         */
    486482        public function test_wp_network_query_cache_with_same_fields_different_count() {
    487             global $wpdb;
    488 
    489483            $q = new WP_Network_Query();
    490484
     
    497491            );
    498492
    499             $number_of_queries = $wpdb->num_queries;
     493            $number_of_queries = get_num_queries();
    500494
    501495            $query_2 = $q->query(
     
    507501                )
    508502            );
    509             $this->assertSame( $number_of_queries + 1, $wpdb->num_queries );
     503            $this->assertSame( $number_of_queries + 1, get_num_queries() );
    510504        }
    511505
     
    569563         */
    570564        public function test_networks_pre_query_filter_should_bypass_database_query() {
    571             global $wpdb;
    572 
    573565            add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
    574566
    575             $num_queries = $wpdb->num_queries;
     567            $num_queries = get_num_queries();
    576568
    577569            $q       = new WP_Network_Query();
     
    581573
    582574            // Make sure no queries were executed.
    583             $this->assertSame( $num_queries, $wpdb->num_queries );
     575            $this->assertSame( $num_queries, get_num_queries() );
    584576
    585577            // We manually inserted a non-existing site and overrode the results with it.
  • 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.
  • trunk/tests/phpunit/tests/option/updateOption.php

    r53865 r55745  
    2929     */
    3030    public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_missing() {
    31         global $wpdb;
    3231        $this->flush_cache();
    3332        update_option( 'test_update_option_default', 'value' );
     
    3736        wp_load_alloptions();
    3837
    39         $before = $wpdb->num_queries;
    40         $value  = get_option( 'test_update_option_default' );
    41         $after  = $wpdb->num_queries;
     38        $before = get_num_queries();
     39        $value  = get_option( 'test_update_option_default' );
     40        $after  = get_num_queries();
    4241
    4342        $this->assertSame( $before, $after );
     
    5352     */
    5453    public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_yes() {
    55         global $wpdb;
    5654        $this->flush_cache();
    5755        update_option( 'test_update_option_default', 'value', 'yes' );
     
    6159        wp_load_alloptions();
    6260
    63         $before = $wpdb->num_queries;
    64         $value  = get_option( 'test_update_option_default' );
    65         $after  = $wpdb->num_queries;
     61        $before = get_num_queries();
     62        $value  = get_option( 'test_update_option_default' );
     63        $after  = get_num_queries();
    6664
    6765        $this->assertSame( $before, $after );
     
    7775     */
    7876    public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_no() {
    79         global $wpdb;
    8077        $this->flush_cache();
    8178        update_option( 'test_update_option_default', 'value', 'no' );
     
    8582        wp_load_alloptions();
    8683
    87         $before = $wpdb->num_queries;
    88         $value  = get_option( 'test_update_option_default' );
    89         $after  = $wpdb->num_queries;
     84        $before = get_num_queries();
     85        $value  = get_option( 'test_update_option_default' );
     86        $after  = get_num_queries();
    9087
    9188        // Database has been hit.
     
    10299     */
    103100    public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_false() {
    104         global $wpdb;
    105101        $this->flush_cache();
    106102        update_option( 'test_update_option_default', 'value', false );
     
    110106        wp_load_alloptions();
    111107
    112         $before = $wpdb->num_queries;
    113         $value  = get_option( 'test_update_option_default' );
    114         $after  = $wpdb->num_queries;
     108        $before = get_num_queries();
     109        $value  = get_option( 'test_update_option_default' );
     110        $after  = get_num_queries();
    115111
    116112        // Database has been hit.
     
    127123     */
    128124    public function test_autoload_should_be_updated_for_existing_option_when_value_is_changed() {
    129         global $wpdb;
    130125        add_option( 'foo', 'bar', '', 'no' );
    131126        $updated = update_option( 'foo', 'bar2', true );
     
    137132        wp_load_alloptions();
    138133
    139         $before = $wpdb->num_queries;
     134        $before = get_num_queries();
    140135        $value  = get_option( 'foo' );
    141136
    142         $this->assertSame( $before, $wpdb->num_queries );
     137        $this->assertSame( $before, get_num_queries() );
    143138        $this->assertSame( $value, 'bar2' );
    144139    }
     
    152147     */
    153148    public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_unchanged() {
    154         global $wpdb;
    155149        add_option( 'foo', 'bar', '', 'yes' );
    156150        $updated = update_option( 'foo', 'bar', false );
     
    162156        wp_load_alloptions();
    163157
    164         $before = $wpdb->num_queries;
     158        $before = get_num_queries();
    165159        $value  = get_option( 'foo' );
    166160
    167161        // 'foo' should still be autoload=yes, so we should see no additional querios.
    168         $this->assertSame( $before, $wpdb->num_queries );
     162        $this->assertSame( $before, get_num_queries() );
    169163        $this->assertSame( $value, 'bar' );
    170164    }
     
    178172     */
    179173    public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_changed_but_no_value_of_autoload_is_provided() {
    180         global $wpdb;
    181174        add_option( 'foo', 'bar', '', 'yes' );
    182175
     
    190183        wp_load_alloptions();
    191184
    192         $before = $wpdb->num_queries;
     185        $before = get_num_queries();
    193186        $value  = get_option( 'foo' );
    194187
    195188        // 'foo' should still be autoload=yes, so we should see no additional queries.
    196         $this->assertSame( $before, $wpdb->num_queries );
     189        $this->assertSame( $before, get_num_queries() );
    197190        $this->assertSame( $value, 'bar2' );
    198191    }
  • trunk/tests/phpunit/tests/option/wpLoadAlloptions.php

    r55256 r55745  
    3535     */
    3636    public function test_if_alloptions_are_retrieved_from_cache() {
    37         global $wpdb;
    38         $before = $wpdb->num_queries;
     37        $before = get_num_queries();
    3938        wp_load_alloptions();
    40         $after = $wpdb->num_queries;
     39        $after = get_num_queries();
    4140
    4241        // Database has not been hit.
     
    5049     */
    5150    public function test_if_alloptions_are_retrieved_from_database() {
    52         global $wpdb;
    53 
    5451        // Delete the existing cache first.
    5552        wp_cache_delete( 'alloptions', 'options' );
    5653
    57         $before = $wpdb->num_queries;
     54        $before = get_num_queries();
    5855        wp_load_alloptions();
    59         $after = $wpdb->num_queries;
     56        $after = get_num_queries();
    6057
    6158        // Database has been hit.
  • trunk/tests/phpunit/tests/post/getPageByPath.php

    r55169 r55745  
    261261     */
    262262    public function test_should_hit_cache() {
    263         global $wpdb;
    264 
    265263        $page = self::factory()->post->create(
    266264            array(
     
    274272        $this->assertSame( $page, $found->ID );
    275273
    276         $num_queries = $wpdb->num_queries;
    277 
    278         $found = get_page_by_path( 'foo' );
    279         $this->assertSame( $page, $found->ID );
    280         $this->assertSame( $num_queries, $wpdb->num_queries );
     274        $num_queries = get_num_queries();
     275
     276        $found = get_page_by_path( 'foo' );
     277        $this->assertSame( $page, $found->ID );
     278        $this->assertSame( $num_queries, get_num_queries() );
    281279    }
    282280
     
    285283     */
    286284    public function test_bad_path_should_be_cached() {
    287         global $wpdb;
    288 
    289285        // Prime cache.
    290286        $found = get_page_by_path( 'foo' );
    291287        $this->assertNull( $found );
    292288
    293         $num_queries = $wpdb->num_queries;
    294 
    295         $found = get_page_by_path( 'foo' );
    296         $this->assertNull( $found );
    297         $this->assertSame( $num_queries, $wpdb->num_queries );
     289        $num_queries = get_num_queries();
     290
     291        $found = get_page_by_path( 'foo' );
     292        $this->assertNull( $found );
     293        $this->assertSame( $num_queries, get_num_queries() );
    298294    }
    299295
     
    302298     */
    303299    public function test_bad_path_served_from_cache_should_not_fall_back_on_current_post() {
    304         global $wpdb, $post;
     300        global $post;
    305301
    306302        // Fake the global.
     
    311307        $this->assertNull( $found );
    312308
    313         $num_queries = $wpdb->num_queries;
    314 
    315         $found = get_page_by_path( 'foo' );
    316         $this->assertNull( $found );
    317         $this->assertSame( $num_queries, $wpdb->num_queries );
     309        $num_queries = get_num_queries();
     310
     311        $found = get_page_by_path( 'foo' );
     312        $this->assertNull( $found );
     313        $this->assertSame( $num_queries, get_num_queries() );
    318314
    319315        unset( $post );
     
    324320     */
    325321    public function test_cache_should_not_match_post_in_different_post_type_with_same_path() {
    326         global $wpdb;
    327 
    328322        register_post_type( 'wptests_pt' );
    329323
     
    346340        $this->assertSame( $p1, $found->ID );
    347341
    348         $num_queries = $wpdb->num_queries;
     342        $num_queries = get_num_queries();
    349343
    350344        $found = get_page_by_path( 'foo', OBJECT, 'wptests_pt' );
    351345        $this->assertSame( $p2, $found->ID );
    352346        $num_queries++;
    353         $this->assertSame( $num_queries, $wpdb->num_queries );
     347        $this->assertSame( $num_queries, get_num_queries() );
    354348    }
    355349
     
    358352     */
    359353    public function test_cache_should_be_invalidated_when_post_name_is_edited() {
    360         global $wpdb;
    361 
    362354        $page = self::factory()->post->create(
    363355            array(
     
    378370        );
    379371
    380         $num_queries = $wpdb->num_queries;
     372        $num_queries = get_num_queries();
    381373
    382374        $found = get_page_by_path( 'bar' );
    383375        $this->assertSame( $page, $found->ID );
    384376        $num_queries++;
    385         $this->assertSame( $num_queries, $wpdb->num_queries );
     377        $this->assertSame( $num_queries, get_num_queries() );
    386378    }
    387379
  • trunk/tests/phpunit/tests/post/getPages.php

    r55590 r55745  
    1111     */
    1212    public function test_get_pages_cache() {
    13         global $wpdb;
    14 
    1513        self::factory()->post->create_many( 3, array( 'post_type' => 'page' ) );
    1614        wp_cache_delete( 'last_changed', 'posts' );
     
    2119        $time1 = wp_cache_get( 'last_changed', 'posts' );
    2220        $this->assertNotEmpty( $time1 );
    23         $num_queries = $wpdb->num_queries;
     21        $num_queries = get_num_queries();
    2422        foreach ( $pages as $page ) {
    2523            $this->assertInstanceOf( 'WP_Post', $page );
     
    3028        $this->assertCount( 3, $pages );
    3129        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    32         $this->assertSame( $num_queries, $wpdb->num_queries );
     30        $this->assertSame( $num_queries, get_num_queries() );
    3331        foreach ( $pages as $page ) {
    3432            $this->assertInstanceOf( 'WP_Post', $page );
     
    4038        $this->assertCount( 2, $pages );
    4139        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    42         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     40        $this->assertSame( $num_queries + 1, get_num_queries() );
    4341        foreach ( $pages as $page ) {
    4442            $this->assertInstanceOf( 'WP_Post', $page );
    4543        }
    4644
    47         $num_queries = $wpdb->num_queries;
     45        $num_queries = get_num_queries();
    4846
    4947        // Again. num_queries and last_changed should remain the same.
     
    5149        $this->assertCount( 2, $pages );
    5250        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    53         $this->assertSame( $num_queries, $wpdb->num_queries );
     51        $this->assertSame( $num_queries, get_num_queries() );
    5452        foreach ( $pages as $page ) {
    5553            $this->assertInstanceOf( 'WP_Post', $page );
     
    6058        $this->assertCount( 3, $pages );
    6159        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    62         $this->assertSame( $num_queries, $wpdb->num_queries );
     60        $this->assertSame( $num_queries, get_num_queries() );
    6361        foreach ( $pages as $page ) {
    6462            $this->assertInstanceOf( 'WP_Post', $page );
     
    6967        $this->assertNotEquals( $time1, $time2 = wp_cache_get( 'last_changed', 'posts' ) );
    7068        get_post( $pages[0]->ID );
    71         $num_queries = $wpdb->num_queries;
     69        $num_queries = get_num_queries();
    7270
    7371        // last_changed bumped so num_queries should increment.
     
    7573        $this->assertCount( 2, $pages );
    7674        $this->assertSame( $time2, wp_cache_get( 'last_changed', 'posts' ) );
    77         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     75        $this->assertSame( $num_queries + 1, get_num_queries() );
    7876        foreach ( $pages as $page ) {
    7977            $this->assertInstanceOf( 'WP_Post', $page );
     
    8886        $this->assertGreaterThan( $old_changed_float, $new_changed_float );
    8987
    90         $num_queries  = $wpdb->num_queries;
     88        $num_queries  = get_num_queries();
    9189        $last_changed = wp_cache_get( 'last_changed', 'posts' );
    9290
     
    9593        $this->assertCount( 2, $pages );
    9694        $this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'posts' ) );
    97         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     95        $this->assertSame( $num_queries + 1, get_num_queries() );
    9896        foreach ( $pages as $page ) {
    9997            $this->assertInstanceOf( 'WP_Post', $page );
     
    105103     */
    106104    public function test_get_pages_cache_empty() {
    107         global $wpdb;
    108 
    109105        wp_cache_delete( 'last_changed', 'posts' );
    110106        $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
    111107
    112         $num_queries = $wpdb->num_queries;
     108        $num_queries = get_num_queries();
    113109
    114110        $pages = get_pages(); // Database gets queried.
    115111
    116         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    117 
    118         $num_queries = $wpdb->num_queries;
     112        $this->assertSame( $num_queries + 1, get_num_queries() );
     113
     114        $num_queries = get_num_queries();
    119115
    120116        $pages = get_pages(); // Database should not get queried.
    121117
    122         $this->assertSame( $num_queries, $wpdb->num_queries );
     118        $this->assertSame( $num_queries, get_num_queries() );
    123119    }
    124120
  • trunk/tests/phpunit/tests/post/getPostClass.php

    r51568 r55745  
    122122     */
    123123    public function test_taxonomy_classes_hit_cache() {
    124         global $wpdb;
    125 
    126124        register_taxonomy( 'wptests_tax', 'post' );
    127125        wp_set_post_terms( $this->post_id, array( 'foo', 'bar' ), 'wptests_tax' );
     
    132130        update_meta_cache( 'post', $this->post_id );
    133131
    134         $num_queries = $wpdb->num_queries;
     132        $num_queries = get_num_queries();
    135133
    136134        $found = get_post_class( '', $this->post_id );
    137135
    138         $this->assertSame( $num_queries, $wpdb->num_queries );
     136        $this->assertSame( $num_queries, get_num_queries() );
    139137    }
    140138}
  • trunk/tests/phpunit/tests/post/query.php

    r55562 r55745  
    556556     */
    557557    public function test_posts_pre_query_filter_should_bypass_database_query() {
    558         global $wpdb;
    559 
    560558        add_filter( 'posts_pre_query', array( __CLASS__, 'filter_posts_pre_query' ) );
    561559
    562         $num_queries = $wpdb->num_queries;
     560        $num_queries = get_num_queries();
    563561        $q           = new WP_Query(
    564562            array(
     
    570568        remove_filter( 'posts_pre_query', array( __CLASS__, 'filter_posts_pre_query' ) );
    571569
    572         $this->assertSame( $num_queries, $wpdb->num_queries );
     570        $this->assertSame( $num_queries, get_num_queries() );
    573571        $this->assertSame( array( 12345 ), $q->posts );
    574572    }
  • trunk/tests/phpunit/tests/query/commentFeed.php

    r53941 r55745  
    2929     */
    3030    public function test_archive_comment_feed() {
    31         global $wpdb;
    3231        add_filter( 'split_the_query', '__return_false' );
    3332        $q1   = new WP_Query();
     
    4342        );
    4443        $q1->query( $args );
    45         $num_queries = $wpdb->num_queries;
     44        $num_queries = get_num_queries();
    4645        $q2          = new WP_Query();
    4746        $q2->query( $args );
    4847        $this->assertTrue( $q2->is_comment_feed() );
    4948        $this->assertFalse( $q2->is_singular() );
    50         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     49        $this->assertSame( $num_queries + 1, get_num_queries() );
    5150    }
    5251
     
    8887     */
    8988    public function test_single_comment_feed() {
    90         global $wpdb;
    9189        $post = get_post( self::$post_ids[0] );
    9290
     
    104102
    105103        $q1->query( $args );
    106         $num_queries = $wpdb->num_queries;
     104        $num_queries = get_num_queries();
    107105        $q2          = new WP_Query();
    108106        $q2->query( $args );
     
    110108        $this->assertTrue( $q2->is_comment_feed() );
    111109        $this->assertTrue( $q2->is_singular() );
    112         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     110        $this->assertSame( $num_queries + 1, get_num_queries() );
    113111    }
    114112}
  • trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php

    r55457 r55745  
    13371337     */
    13381338    public function test_object_term_queries_are_cached() {
    1339         global $wpdb;
    1340 
    13411339        $tags = self::factory()->tag->create_many( 2 );
    13421340        $p    = self::factory()->post->create();
     
    13501348        unset( $request, $response );
    13511349
    1352         $num_queries = $wpdb->num_queries;
     1350        $num_queries = get_num_queries();
    13531351
    13541352        $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
     
    13581356
    13591357        $this->assertSameSets( $found_1, $found_2 );
    1360         $this->assertSame( $num_queries, $wpdb->num_queries );
     1358        $this->assertSame( $num_queries, get_num_queries() );
    13611359    }
    13621360
  • trunk/tests/phpunit/tests/term/cache.php

    r54090 r55745  
    102102
    103103    public function test_get_term_should_update_term_cache_when_passed_an_object() {
    104         global $wpdb;
    105 
    106104        register_taxonomy( 'wptests_tax', 'post' );
    107105        $term = self::factory()->term->create(
     
    117115        $this->assertEmpty( wp_cache_get( $term, 'terms' ) );
    118116
    119         $num_queries = $wpdb->num_queries;
     117        $num_queries = get_num_queries();
    120118
    121119        // get_term() will only be update the cache if the 'filter' prop is unset.
     
    125123
    126124        // No new queries should have fired.
    127         $this->assertSame( $num_queries, $wpdb->num_queries );
     125        $this->assertSame( $num_queries, get_num_queries() );
    128126        $this->assertSame( $term_object, $term_object_2 );
    129127    }
    130128
    131129    public function test_get_term_should_update_term_cache_when_passed_a_valid_term_identifier() {
    132         global $wpdb;
    133 
    134130        register_taxonomy( 'wptests_tax', 'post' );
    135131        $term = self::factory()->term->create(
     
    144140        $this->assertEmpty( wp_cache_get( $term, 'terms' ) );
    145141
    146         $num_queries = $wpdb->num_queries;
     142        $num_queries = get_num_queries();
    147143
    148144        // Prime cache.
    149145        $term_object = get_term( $term, 'wptests_tax' );
    150146        $this->assertNotEmpty( wp_cache_get( $term, 'terms' ) );
    151         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     147        $this->assertSame( $num_queries + 1, get_num_queries() );
    152148
    153149        $term_object_2 = get_term( $term, 'wptests_tax' );
    154150
    155151        // No new queries should have fired.
    156         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     152        $this->assertSame( $num_queries + 1, get_num_queries() );
    157153        $this->assertEquals( $term_object, $term_object_2 );
    158154    }
    159155
    160156    public function test_get_term_by_should_update_term_cache_when_passed_a_valid_term_identifier() {
    161         global $wpdb;
    162 
    163157        register_taxonomy( 'wptests_tax', 'post' );
    164158        $term = self::factory()->term->create(
     
    173167        $this->assertEmpty( wp_cache_get( $term, 'terms' ) );
    174168
    175         $num_queries = $wpdb->num_queries;
     169        $num_queries = get_num_queries();
    176170
    177171        // Prime cache.
    178172        $term_object = get_term_by( 'id', $term, 'wptests_tax' );
    179173        $this->assertNotEmpty( wp_cache_get( $term, 'terms' ) );
    180         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     174        $this->assertSame( $num_queries + 1, get_num_queries() );
    181175
    182176        $term_object_2 = get_term( $term, 'wptests_tax' );
    183177
    184178        // No new queries should have fired.
    185         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     179        $this->assertSame( $num_queries + 1, get_num_queries() );
    186180        $this->assertEquals( $term_object, $term_object_2 );
    187181    }
     
    191185     */
    192186    public function test_get_terms_should_update_cache_for_located_terms() {
    193         global $wpdb;
    194 
    195187        register_taxonomy( 'wptests_tax', 'post' );
    196188
     
    209201        );
    210202
    211         $num_queries = $wpdb->num_queries;
     203        $num_queries = get_num_queries();
    212204
    213205        foreach ( $terms as $term_id ) {
     
    215207        }
    216208
    217         $this->assertSame( $num_queries, $wpdb->num_queries );
     209        $this->assertSame( $num_queries, get_num_queries() );
    218210
    219211        _unregister_taxonomy( 'wptests_tax' );
     
    243235     */
    244236    public function test_get_term_by_slug_cache() {
    245         global $wpdb;
    246 
    247237        $term_id = self::factory()->term->create(
    248238            array(
     
    254244
    255245        clean_term_cache( $term_id, 'post_tag' );
    256         $num_queries = $wpdb->num_queries;
     246        $num_queries = get_num_queries();
    257247
    258248        $term        = get_term_by( 'slug', 'burrito', 'post_tag' );
    259249        $num_queries = $num_queries + 2;
    260250        $this->assertSame( 'Taco', $term->name );
    261         $this->assertSame( $num_queries, $wpdb->num_queries );
     251        $this->assertSame( $num_queries, get_num_queries() );
    262252
    263253        // This should now hit cache.
    264254        $term = get_term_by( 'slug', 'burrito', 'post_tag' );
    265255        $this->assertSame( 'Taco', $term->name );
    266         $this->assertSame( $num_queries, $wpdb->num_queries );
     256        $this->assertSame( $num_queries, get_num_queries() );
    267257
    268258        $this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
    269         $this->assertSame( $num_queries, $wpdb->num_queries );
     259        $this->assertSame( $num_queries, get_num_queries() );
    270260    }
    271261
     
    274264     */
    275265    public function test_get_term_by_slug_cache_update() {
    276         global $wpdb;
    277 
    278266        $term_id = self::factory()->term->create(
    279267            array(
     
    285273
    286274        clean_term_cache( $term_id, 'post_tag' );
    287         $num_queries = $wpdb->num_queries;
     275        $num_queries = get_num_queries();
    288276
    289277        $term        = get_term_by( 'slug', 'burrito', 'post_tag' );
    290278        $num_queries = $num_queries + 2;
    291279        $this->assertSame( 'Taco', $term->name );
    292         $this->assertSame( $num_queries, $wpdb->num_queries );
     280        $this->assertSame( $num_queries, get_num_queries() );
    293281
    294282        // This should now hit cache.
    295283        $term = get_term_by( 'slug', 'burrito', 'post_tag' );
    296284        $this->assertSame( 'Taco', $term->name );
    297         $this->assertSame( $num_queries, $wpdb->num_queries );
     285        $this->assertSame( $num_queries, get_num_queries() );
    298286
    299287        // Update the tag which invalidates the cache.
    300288        wp_update_term( $term_id, 'post_tag', array( 'name' => 'No Taco' ) );
    301         $num_queries = $wpdb->num_queries;
     289        $num_queries = get_num_queries();
    302290
    303291        // This should not hit cache.
     
    305293        $num_queries = $num_queries + 2;
    306294        $this->assertSame( 'No Taco', $term->name );
    307         $this->assertSame( $num_queries, $wpdb->num_queries );
     295        $this->assertSame( $num_queries, get_num_queries() );
    308296    }
    309297
     
    312300     */
    313301    public function test_get_term_by_name_cache() {
    314         global $wpdb;
    315 
    316302        $term_id = self::factory()->term->create(
    317303            array(
     
    323309
    324310        clean_term_cache( $term_id, 'post_tag' );
    325         $num_queries = $wpdb->num_queries;
     311        $num_queries = get_num_queries();
    326312
    327313        get_term_by( 'name', 'Burrito', 'post_tag' );
    328314        $num_queries = $num_queries + 2;
    329         $this->assertSame( $num_queries, $wpdb->num_queries );
     315        $this->assertSame( $num_queries, get_num_queries() );
    330316
    331317        // This should now hit cache.
    332318        $term = get_term_by( 'name', 'Burrito', 'post_tag' );
    333         $this->assertSame( $num_queries, $wpdb->num_queries );
     319        $this->assertSame( $num_queries, get_num_queries() );
    334320
    335321        $this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
    336         $this->assertSame( $num_queries, $wpdb->num_queries );
     322        $this->assertSame( $num_queries, get_num_queries() );
    337323    }
    338324
     
    341327     */
    342328    public function test_get_term_by_name_cache_update() {
    343         global $wpdb;
    344 
    345329        $term_id = self::factory()->term->create(
    346330            array(
     
    352336
    353337        clean_term_cache( $term_id, 'post_tag' );
    354         $num_queries = $wpdb->num_queries;
     338        $num_queries = get_num_queries();
    355339
    356340        get_term_by( 'name', 'Burrito', 'post_tag' );
    357341        $num_queries = $num_queries + 2;
    358         $this->assertSame( $num_queries, $wpdb->num_queries );
     342        $this->assertSame( $num_queries, get_num_queries() );
    359343
    360344        // This should now hit cache.
    361345        get_term_by( 'name', 'Burrito', 'post_tag' );
    362         $this->assertSame( $num_queries, $wpdb->num_queries );
     346        $this->assertSame( $num_queries, get_num_queries() );
    363347
    364348        // Update the tag which invalidates the cache.
    365349        wp_update_term( $term_id, 'post_tag', array( 'slug' => 'taco' ) );
    366         $num_queries = $wpdb->num_queries;
     350        $num_queries = get_num_queries();
    367351
    368352        // This should not hit cache.
    369353        get_term_by( 'name', 'burrito', 'post_tag' );
    370354        $num_queries = $num_queries + 2;
    371         $this->assertSame( $num_queries, $wpdb->num_queries );
     355        $this->assertSame( $num_queries, get_num_queries() );
    372356    }
    373357
     
    376360     */
    377361    public function test_invalidating_term_caches_should_fail_when_invalidation_is_suspended() {
    378         global $wpdb;
    379 
    380362        $term_id = self::factory()->term->create(
    381363            array(
     
    386368
    387369        clean_term_cache( $term_id, 'post_tag' );
    388         $num_queries  = $wpdb->num_queries;
     370        $num_queries  = get_num_queries();
    389371        $last_changed = wp_cache_get( 'last_changed', 'terms' );
    390372
     
    394376        // Verify the term is cached.
    395377        $term2 = get_term_by( 'name', 'Burrito', 'post_tag' );
    396         $this->assertSame( $num_queries, $wpdb->num_queries );
     378        $this->assertSame( $num_queries, get_num_queries() );
    397379        $this->assertEquals( $term1, $term2 );
    398380
     
    401383        // Update the tag.
    402384        wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) );
    403         $num_queries = $wpdb->num_queries;
     385        $num_queries = get_num_queries();
    404386
    405387        // Verify that the cached term still matches the initial cached term.
    406388        $term3 = get_term_by( 'name', 'Burrito', 'post_tag' );
    407         $this->assertSame( $num_queries, $wpdb->num_queries );
     389        $this->assertSame( $num_queries, get_num_queries() );
    408390        $this->assertEquals( $term1, $term3 );
    409391
     
    419401     */
    420402    public function test_get_term_by_does_not_prime_term_meta_cache() {
    421         global $wpdb;
    422 
    423403        $term_id = self::factory()->term->create(
    424404            array(
     
    430410
    431411        clean_term_cache( $term_id, 'post_tag' );
    432         $num_queries = $wpdb->num_queries;
     412        $num_queries = get_num_queries();
    433413
    434414        $term        = get_term_by( 'name', 'Burrito', 'post_tag' );
     
    436416        $this->assertInstanceOf( 'WP_Term', $term );
    437417        $this->assertSame( $term_id, $term->term_id );
    438         $this->assertSame( $num_queries, $wpdb->num_queries );
     418        $this->assertSame( $num_queries, get_num_queries() );
    439419
    440420        $term_meta = get_term_meta( $term_id, 'foo', true );
    441421        $num_queries++;
    442422        $this->assertSame( $term_meta, 'bar' );
    443         $this->assertSame( $num_queries, $wpdb->num_queries );
     423        $this->assertSame( $num_queries, get_num_queries() );
    444424    }
    445425
  • 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 );
  • 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
  • trunk/tests/phpunit/tests/term/getTerms.php

    r55671 r55745  
    135135     */
    136136    public function test_get_terms_cache() {
    137         global $wpdb;
    138 
    139137        $this->set_up_three_posts_and_tags();
    140138
    141         $num_queries = $wpdb->num_queries;
     139        $num_queries = get_num_queries();
    142140
    143141        // last_changed and num_queries should bump.
     
    146144        $time1 = wp_cache_get( 'last_changed', 'terms' );
    147145        $this->assertNotEmpty( $time1 );
    148         $this->assertSame( $num_queries + 2, $wpdb->num_queries );
    149 
    150         $num_queries = $wpdb->num_queries;
     146        $this->assertSame( $num_queries + 2, get_num_queries() );
     147
     148        $num_queries = get_num_queries();
    151149
    152150        // Again. last_changed and num_queries should remain the same.
     
    154152        $this->assertCount( 3, $terms );
    155153        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) );
    156         $this->assertSame( $num_queries, $wpdb->num_queries );
     154        $this->assertSame( $num_queries, get_num_queries() );
    157155    }
    158156
     
    168166        $terms       = get_terms( 'post_tag' );
    169167        $time1       = wp_cache_get( 'last_changed', 'terms' );
    170         $num_queries = $wpdb->num_queries;
     168        $num_queries = get_num_queries();
    171169
    172170        // num_queries should bump, last_changed should remain the same.
     
    174172        $this->assertCount( 2, $terms );
    175173        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) );
    176         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    177 
    178         $num_queries = $wpdb->num_queries;
     174        $this->assertSame( $num_queries + 1, get_num_queries() );
     175
     176        $num_queries = get_num_queries();
    179177
    180178        // Again. last_changed and num_queries should remain the same.
     
    182180        $this->assertCount( 2, $terms );
    183181        $this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) );
    184         $this->assertSame( $num_queries, $wpdb->num_queries );
     182        $this->assertSame( $num_queries, get_num_queries() );
    185183    }
    186184
     
    196194        $terms       = get_terms( 'post_tag' );
    197195        $time1       = wp_cache_get( 'last_changed', 'terms' );
    198         $num_queries = $wpdb->num_queries;
     196        $num_queries = get_num_queries();
    199197
    200198        // Force last_changed to bump.
    201199        wp_delete_term( $terms[0]->term_id, 'post_tag' );
    202200
    203         $num_queries = $wpdb->num_queries;
     201        $num_queries = get_num_queries();
    204202        $time2       = wp_cache_get( 'last_changed', 'terms' );
    205203        $this->assertNotEquals( $time1, $time2 );
     
    209207        $this->assertCount( 2, $terms );
    210208        $this->assertSame( $time2, wp_cache_get( 'last_changed', 'terms' ) );
    211         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
    212 
    213         $num_queries = $wpdb->num_queries;
     209        $this->assertSame( $num_queries + 1, get_num_queries() );
     210
     211        $num_queries = get_num_queries();
    214212
    215213        // Again. last_changed and num_queries should remain the same.
     
    217215        $this->assertCount( 2, $terms );
    218216        $this->assertSame( $time2, wp_cache_get( 'last_changed', 'terms' ) );
    219         $this->assertSame( $num_queries, $wpdb->num_queries );
     217        $this->assertSame( $num_queries, get_num_queries() );
    220218
    221219        // @todo Repeat with term insert and update.
     
    849847     */
    850848    public function test_child_of_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
    851         global $wpdb;
    852 
    853849        register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
    854850
    855851        $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
    856852
    857         $num_queries = $wpdb->num_queries;
     853        $num_queries = get_num_queries();
    858854
    859855        $found = get_terms(
     
    866862
    867863        $this->assertEmpty( $found );
    868         $this->assertSame( $num_queries, $wpdb->num_queries );
     864        $this->assertSame( $num_queries, get_num_queries() );
    869865    }
    870866
     
    24742470     */
    24752471    public function test_parent_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
    2476         global $wpdb;
    2477 
    24782472        register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
    24792473
    24802474        $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
    24812475
    2482         $num_queries = $wpdb->num_queries;
     2476        $num_queries = get_num_queries();
    24832477
    24842478        $found = get_terms(
     
    24912485
    24922486        $this->assertEmpty( $found );
    2493         $this->assertSame( $num_queries, $wpdb->num_queries );
     2487        $this->assertSame( $num_queries, get_num_queries() );
    24942488    }
    24952489
     
    27742768        );
    27752769
    2776         $num_queries = $wpdb->num_queries;
     2770        $num_queries = get_num_queries();
    27772771
    27782772        foreach ( $terms as $t ) {
     
    27802774        }
    27812775
    2782         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     2776        $this->assertSame( $num_queries + 1, get_num_queries() );
    27832777    }
    27842778
     
    28042798        );
    28052799
    2806         $num_queries = $wpdb->num_queries;
     2800        $num_queries = get_num_queries();
    28072801
    28082802        foreach ( $terms as $t ) {
     
    28102804        }
    28112805
    2812         $this->assertSame( $num_queries + 3, $wpdb->num_queries );
     2806        $this->assertSame( $num_queries + 3, get_num_queries() );
    28132807    }
    28142808
     
    29092903        );
    29102904
    2911         $num_queries = $wpdb->num_queries;
     2905        $num_queries = get_num_queries();
    29122906
    29132907        $found = get_terms(
     
    29192913        );
    29202914
    2921         $this->assertSame( $num_queries, $wpdb->num_queries );
     2915        $this->assertSame( $num_queries, get_num_queries() );
    29222916
    29232917        $this->assertNotEmpty( $found );
     
    29322926     */
    29332927    public function test_should_prime_individual_term_cache_when_fields_is_all() {
    2934         global $wpdb;
    2935 
    29362928        register_taxonomy( 'wptests_tax', 'post' );
    29372929        $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     
    29452937        );
    29462938
    2947         $num_queries = $wpdb->num_queries;
     2939        $num_queries = get_num_queries();
    29482940        $term0       = get_term( $terms[0] );
    2949         $this->assertSame( $num_queries, $wpdb->num_queries );
     2941        $this->assertSame( $num_queries, get_num_queries() );
    29502942
    29512943    }
  • trunk/tests/phpunit/tests/term/getTheTerms.php

    r52010 r55745  
    198198     */
    199199    public function test_uncached_terms_should_be_primed_with_a_single_query() {
    200         global $wpdb;
    201 
    202200        register_taxonomy( 'wptests_tax', 'post' );
    203201
     
    211209        clean_term_cache( array( $terms[0], $terms[1] ), 'wptests_tax', false );
    212210
    213         $num_queries = $wpdb->num_queries;
     211        $num_queries = get_num_queries();
    214212        $found       = get_the_terms( self::$post_ids[0], 'wptests_tax' );
    215213
     
    217215
    218216        $num_queries++;
    219         $this->assertSame( $num_queries, $wpdb->num_queries );
     217        $this->assertSame( $num_queries, get_num_queries() );
    220218
    221219    }
  • trunk/tests/phpunit/tests/term/isObjectInTerm.php

    r55365 r55745  
    136136     */
    137137    public function test_should_populate_and_hit_relationships_cache() {
    138         global $wpdb;
    139 
    140138        register_taxonomy( 'wptests_tax', 'post' );
    141139        $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     
    144142        wp_set_object_terms( $o, $terms[0], 'wptests_tax' );
    145143
    146         $num_queries = $wpdb->num_queries;
     144        $num_queries = get_num_queries();
    147145        $this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[0] ) );
    148146        $num_queries = $num_queries + 2;
    149         $this->assertSame( $num_queries, $wpdb->num_queries );
     147        $this->assertSame( $num_queries, get_num_queries() );
    150148
    151149        $this->assertFalse( is_object_in_term( $o, 'wptests_tax', $terms[1] ) );
    152         $this->assertSame( $num_queries, $wpdb->num_queries );
     150        $this->assertSame( $num_queries, get_num_queries() );
    153151    }
    154152
     
    157155     */
    158156    public function test_should_not_be_fooled_by_a_stale_relationship_cache() {
    159         global $wpdb;
    160 
    161157        register_taxonomy( 'wptests_tax', 'post' );
    162158        $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     
    165161        wp_set_object_terms( $o, $terms[0], 'wptests_tax' );
    166162
    167         $num_queries = $wpdb->num_queries;
     163        $num_queries = get_num_queries();
    168164        $this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[0] ) );
    169165        $num_queries = $num_queries + 2;
    170         $this->assertSame( $num_queries, $wpdb->num_queries );
     166        $this->assertSame( $num_queries, get_num_queries() );
    171167
    172168        wp_set_object_terms( $o, $terms[1], 'wptests_tax' );
    173169
    174         $num_queries = $wpdb->num_queries;
     170        $num_queries = get_num_queries();
    175171        $this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[1] ) );
    176172        $num_queries = $num_queries + 2;
    177         $this->assertSame( $num_queries, $wpdb->num_queries );
     173        $this->assertSame( $num_queries, get_num_queries() );
    178174    }
    179175
  • trunk/tests/phpunit/tests/term/meta.php

    r55671 r55745  
    115115
    116116    public function test_term_meta_should_be_lazy_loaded_for_all_terms_in_wp_query_loop() {
    117         global $wpdb;
    118 
    119117        $p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    120118
     
    140138
    141139                // First request will hit the database.
    142                 $num_queries = $wpdb->num_queries;
     140                $num_queries = get_num_queries();
    143141                $this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) );
    144142                $num_queries++;
    145                 $this->assertSame( $num_queries, $wpdb->num_queries );
     143                $this->assertSame( $num_queries, get_num_queries() );
    146144
    147145                // Second and third requests should be in cache.
    148146                $this->assertSame( 'bar', get_term_meta( $terms[1], 'foo', true ) );
    149147                $this->assertSame( 'bar', get_term_meta( $terms[2], 'foo', true ) );
    150                 $this->assertSame( $num_queries, $wpdb->num_queries );
     148                $this->assertSame( $num_queries, get_num_queries() );
    151149
    152150                // Querying a term not primed should result in a hit.
    153151                $num_queries++;
    154152                $this->assertSame( 'bar', get_term_meta( $orphan_term, 'foo', true ) );
    155                 $this->assertSame( $num_queries, $wpdb->num_queries );
     153                $this->assertSame( $num_queries, get_num_queries() );
    156154            }
    157155        }
     
    187185     */
    188186    public function test_lazy_load_term_meta_false() {
    189         global $wpdb;
    190 
    191187        $p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    192188
     
    211207
    212208                // Requests will hit the database.
    213                 $num_queries = $wpdb->num_queries;
     209                $num_queries = get_num_queries();
    214210                $this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) );
    215211                $num_queries++;
    216                 $this->assertSame( $num_queries, $wpdb->num_queries );
     212                $this->assertSame( $num_queries, get_num_queries() );
    217213
    218214                $this->assertSame( 'bar', get_term_meta( $terms[1], 'foo', true ) );
    219215                $num_queries++;
    220                 $this->assertSame( $num_queries, $wpdb->num_queries );
     216                $this->assertSame( $num_queries, get_num_queries() );
    221217            }
    222218        }
  • 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.
  • trunk/tests/phpunit/tests/term/termExists.php

    r52921 r55745  
    321321     */
    322322    public function test_term_exists_caching() {
    323         global $wpdb;
    324323        register_taxonomy( 'wptests_tax', 'post' );
    325324
     
    332331        );
    333332        $this->assertEquals( $t, term_exists( $slug ) );
    334         $num_queries = $wpdb->num_queries;
     333        $num_queries = get_num_queries();
    335334        $this->assertEquals( $t, term_exists( $slug ) );
    336         $this->assertSame( $num_queries, $wpdb->num_queries );
     335        $this->assertSame( $num_queries, get_num_queries() );
    337336
    338337        $this->assertTrue( wp_delete_term( $t, 'wptests_tax' ) );
    339         $num_queries = $wpdb->num_queries;
     338        $num_queries = get_num_queries();
    340339        $this->assertNull( term_exists( $slug ) );
    341         $this->assertSame( $num_queries + 2, $wpdb->num_queries );
     340        $this->assertSame( $num_queries + 2, get_num_queries() );
    342341
    343342        // Clean up.
     
    350349     */
    351350    public function test_term_exists_caching_suspend_cache_invalidation() {
    352         global $wpdb;
    353351        register_taxonomy( 'wptests_tax', 'post' );
    354352
     
    363361
    364362        $this->assertEquals( $t, term_exists( $slug ) );
    365         $num_queries = $wpdb->num_queries;
     363        $num_queries = get_num_queries();
    366364        $this->assertEquals( $t, term_exists( $slug ) );
    367         $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     365        $this->assertSame( $num_queries + 1, get_num_queries() );
    368366        wp_suspend_cache_invalidation( false );
    369367
  • 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
  • trunk/tests/phpunit/tests/user/query.php

    r55562 r55745  
    17211721     */
    17221722    public function test_users_pre_query_filter_should_bypass_database_query() {
    1723         global $wpdb;
    1724 
    17251723        add_filter( 'users_pre_query', array( __CLASS__, 'filter_users_pre_query' ), 10, 2 );
    17261724
    1727         $num_queries = $wpdb->num_queries;
     1725        $num_queries = get_num_queries();
    17281726        $q           = new WP_User_Query(
    17291727            array(
     
    17351733
    17361734        // Make sure no queries were executed.
    1737         $this->assertSame( $num_queries, $wpdb->num_queries );
     1735        $this->assertSame( $num_queries, get_num_queries() );
    17381736
    17391737        // We manually inserted a non-existing user and overrode the results with it.
Note: See TracChangeset for help on using the changeset viewer.