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
@@ -34,10 +34,9 @@ class Tests_Option_wpLoadAlloptions extends WP_UnitTestCase {
* @covers ::wp_load_alloptions
*/
public function test_if_alloptions_are_retrieved_from_cache() {
global $wpdb;
$before = $wpdb->num_queries;
$before = get_num_queries();
wp_load_alloptions();
$after = $wpdb->num_queries;
$after = get_num_queries();
// Database has not been hit.
$this->assertSame( $before, $after );
@@ -49,14 +48,12 @@ class Tests_Option_wpLoadAlloptions extends WP_UnitTestCase {
* @covers ::wp_load_alloptions
*/
public function test_if_alloptions_are_retrieved_from_database() {
global $wpdb;
// Delete the existing cache first.
wp_cache_delete( 'alloptions', 'options' );
$before = $wpdb->num_queries;
$before = get_num_queries();
wp_load_alloptions();
$after = $wpdb->num_queries;
$after = get_num_queries();
// Database has been hit.
$this->assertSame( $before + 1, $after );