Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (10 years ago)
Author:
wonderboymusic
Message:

Unit Tests: one $factory to rule them all, and it shall be static.

Using more than one instance of WP_UnitTest_Factory causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use setUpBeforeClass, we were creating ad hoc instances. To avoid that, we were injecting one static instance via Dependency Injection in wpSetUpBeforeClass. All tests should really use the static instance, so we will remove the instance prop $factory.

Replace $this->factory with self::$factory over 2000 times.
Rewrite all of the tests that were hard-coding dynamic values.

#YOLOFriday

File:
1 edited

Legend:

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

    r34172 r35225  
    3838     */
    3939    function test_get_main_network_id_two_networks() {
    40         $this->factory->network->create();
     40        self::$factory->network->create();
    4141
    4242        $this->assertEquals( 1, get_main_network_id() );
     
    5050        global $current_site;
    5151
    52         $id = $this->factory->network->create();
     52        $id = self::$factory->network->create();
    5353
    5454        $current_site->id = (int) $id;
     
    6666    function test_get_main_network_id_after_network_delete() {
    6767        global $wpdb, $current_site;
    68         $id = $this->factory->network->create();
     68        $id = self::$factory->network->create();
    6969
    7070        $current_site->id = (int) $id;
     
    9191        // false for large networks by default
    9292        add_filter( 'enable_live_network_counts', '__return_false' );
    93         $this->factory->blog->create_many( 4 );
     93        self::$factory->blog->create_many( 4 );
    9494
    9595        // count only updated when cron runs, so unchanged
     
    9797
    9898        add_filter( 'enable_live_network_counts', '__return_true' );
    99         $site_ids = $this->factory->blog->create_many( 4 );
     99        $site_ids = self::$factory->blog->create_many( 4 );
    100100
    101101        $this->assertEquals( $site_count_start + 9, (int) get_blog_count() );
     
    212212        // Only false for large networks as of 3.7
    213213        add_filter( 'enable_live_network_counts', '__return_false' );
    214         $this->factory->user->create( array( 'role' => 'administrator' ) );
     214        self::$factory->user->create( array( 'role' => 'administrator' ) );
    215215
    216216        $count = get_user_count(); // No change, cache not refreshed
     
    241241        $this->assertEquals( 1, $dashboard_blog->blog_id );
    242242
    243         $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    244         $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id ) );
     243        $user_id = self::$factory->user->create( array( 'role' => 'administrator' ) );
     244        $blog_id = self::$factory->blog->create( array( 'user_id' => $user_id ) );
    245245        $this->assertInternalType( 'int', $blog_id );
    246246
Note: See TracChangeset for help on using the changeset viewer.