Make WordPress Core


Ignore:
Timestamp:
05/11/2023 10:05:51 AM (19 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/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 ) );
Note: See TracChangeset for help on using the changeset viewer.