WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/network.php

    r47013 r48937  
    7777         */
    7878        function test_get_main_network_id_default() {
    79             $this->assertEquals( 1, get_main_network_id() );
     79            $this->assertSame( 1, get_main_network_id() );
    8080        }
    8181
     
    8787            self::factory()->network->create();
    8888
    89             $this->assertEquals( 1, get_main_network_id() );
     89            $this->assertSame( 1, get_main_network_id() );
    9090        }
    9191
     
    101101            $current_site->id = (int) $id;
    102102
    103             $this->assertEquals( 1, get_main_network_id() );
     103            $this->assertSame( 1, get_main_network_id() );
    104104        }
    105105
     
    121121            $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->site} SET id=1 WHERE id=%d", $temp_id ) );
    122122
    123             $this->assertEquals( self::$different_network_id, $main_network_id );
     123            $this->assertSame( self::$different_network_id, $main_network_id );
    124124        }
    125125
    126126        function test_get_main_network_id_filtered() {
    127127            add_filter( 'get_main_network_id', array( $this, '_get_main_network_id' ) );
    128             $this->assertEquals( 3, get_main_network_id() );
     128            $this->assertSame( 3, get_main_network_id() );
    129129            remove_filter( 'get_main_network_id', array( $this, '_get_main_network_id' ) );
    130130        }
     
    160160            wp_update_network_counts();
    161161
    162             $this->assertEquals( $site_count_start + 1, $actual );
     162            $this->assertSame( $site_count_start + 1, $actual );
    163163        }
    164164
     
    247247            $count = get_user_count();
    248248
    249             $this->assertEquals( $start_count, $count );
     249            $this->assertSame( $start_count, $count );
    250250
    251251            wp_update_network_counts();
     
    269269            activate_plugin( $path ); // Enable the plugin for the current site.
    270270            $active_plugins = wp_get_active_network_plugins();
    271             $this->assertEquals( array(), $active_plugins );
     271            $this->assertSame( array(), $active_plugins );
    272272
    273273            add_action( 'deactivated_plugin', array( $this, '_helper_deactivate_hook' ) );
     
    276276            activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
    277277            $active_plugins = wp_get_active_network_plugins();
    278             $this->assertEquals( array( WP_PLUGIN_DIR . '/hello.php' ), $active_plugins );
     278            $this->assertSame( array( WP_PLUGIN_DIR . '/hello.php' ), $active_plugins );
    279279
    280280            // Deactivate the plugin.
    281281            deactivate_plugins( $path );
    282282            $active_plugins = wp_get_active_network_plugins();
    283             $this->assertEquals( array(), $active_plugins );
    284 
    285             $this->assertEquals( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
     283            $this->assertSame( array(), $active_plugins );
     284
     285            $this->assertSame( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
    286286
    287287            activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
    288288            deactivate_plugins( $path, true );  // Silent mode.
    289289
    290             $this->assertEquals( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
     290            $this->assertSame( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
    291291        }
    292292
     
    303303            $active_plugins = wp_get_active_network_plugins();
    304304            $this->assertCount( 1, $active_plugins );
    305             $this->assertEquals( 1, $mock->get_call_count() );
     305            $this->assertSame( 1, $mock->get_call_count() );
    306306
    307307            // Should do nothing on the second try.
     
    309309            $active_plugins = wp_get_active_network_plugins();
    310310            $this->assertCount( 1, $active_plugins );
    311             $this->assertEquals( 1, $mock->get_call_count() );
     311            $this->assertSame( 1, $mock->get_call_count() );
    312312
    313313            remove_action( 'activate_' . $path, array( $mock, 'action' ) );
     
    338338
    339339            $count = get_user_count(); // No change, cache not refreshed.
    340             $this->assertEquals( $start_count, $count );
     340            $this->assertSame( $start_count, $count );
    341341
    342342            wp_update_network_counts(); // Magic happens here.
     
    393393
    394394            $result = get_blog_count();
    395             $this->assertEquals( $expected, $result );
     395            $this->assertSame( $expected, $result );
    396396        }
    397397
     
    405405
    406406            $result = get_blog_count( self::$different_network_id );
    407             $this->assertEquals( 3, $result );
     407            $this->assertSame( 3, $result );
    408408        }
    409409
     
    421421
    422422            $result = get_user_count();
    423             $this->assertEquals( $expected, $result );
     423            $this->assertSame( $expected, $result );
    424424        }
    425425
     
    437437
    438438            $result = get_user_count( self::$different_network_id );
    439             $this->assertEquals( $expected, $result );
     439            $this->assertSame( $expected, $result );
    440440        }
    441441
     
    597597            wpmu_delete_blog( $site_id, true );
    598598
    599             $this->assertEquals( $original_count + 1, $result );
     599            $this->assertSame( $original_count + 1, $result );
    600600        }
    601601
     
    633633
    634634            // Double-check we got the ID of the new network correct.
    635             $this->assertEquals( $new_network_id, $new_network->id );
     635            $this->assertSame( $new_network_id, $new_network->id );
    636636
    637637            // Verify that if we fetch the network now, it's no longer false.
    638638            $fetched_network = get_network( $new_network_id );
    639639            $this->assertInstanceOf( 'WP_Network', $fetched_network );
    640             $this->assertEquals( $new_network_id, $fetched_network->id );
     640            $this->assertSame( $new_network_id, $fetched_network->id );
    641641        }
    642642
Note: See TracChangeset for help on using the changeset viewer.