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.

git-svn-id: https://develop.svn.wordpress.org/trunk@55745 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2023-05-11 10:05:51 +00:00
parent 55ee499f4e
commit 07fc459e7a
32 changed files with 283 additions and 430 deletions
+4 -6
View File
@@ -28,7 +28,6 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
* @ticket 36904
*/
public function test_archive_comment_feed() {
global $wpdb;
add_filter( 'split_the_query', '__return_false' );
$q1 = new WP_Query();
$args = array(
@@ -42,12 +41,12 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
'cache_results' => false,
);
$q1->query( $args );
$num_queries = $wpdb->num_queries;
$num_queries = get_num_queries();
$q2 = new WP_Query();
$q2->query( $args );
$this->assertTrue( $q2->is_comment_feed() );
$this->assertFalse( $q2->is_singular() );
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
$this->assertSame( $num_queries + 1, get_num_queries() );
}
/**
@@ -87,7 +86,6 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
* @ticket 36904
*/
public function test_single_comment_feed() {
global $wpdb;
$post = get_post( self::$post_ids[0] );
$q1 = new WP_Query();
@@ -103,12 +101,12 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
);
$q1->query( $args );
$num_queries = $wpdb->num_queries;
$num_queries = get_num_queries();
$q2 = new WP_Query();
$q2->query( $args );
$this->assertTrue( $q2->is_comment_feed() );
$this->assertTrue( $q2->is_singular() );
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
$this->assertSame( $num_queries + 1, get_num_queries() );
}
}