Make WordPress Core


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.