Make WordPress Core


Ignore:
Timestamp:
05/11/2023 10:05:51 AM (3 years ago)
Author:
spacedmonkey
Message:

Tests: Use the function get_num_queries across all unit tests.

Replace use of $wpdb->num_queries with a function call to get_num_queries. This improves readability and consistency between tests.

Props SergeyBiryukov, peterwilsoncc, spacedmonkey.
See #57841.

File:
1 edited

Legend:

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