Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (9 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/customize/nav-menus.php

    r35162 r35225  
    2323        parent::setUp();
    2424        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    25         wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     25        wp_set_current_user( self::$factory->user->create( array( 'role' => 'administrator' ) ) );
    2626        global $wp_customize;
    2727        $this->wp_customize = new WP_Customize_Manager();
     
    125125
    126126        // Create pages.
    127         $this->factory->post->create_many( 12, array( 'post_type' => 'page' ) );
     127        self::$factory->post->create_many( 12, array( 'post_type' => 'page' ) );
    128128
    129129        // Home is included in menu items when page is zero.
     
    146146
    147147        // Create page.
    148         $post_id = $this->factory->post->create( array( 'post_title' => 'Post Title' ) );
     148        $post_id = self::$factory->post->create( array( 'post_title' => 'Post Title' ) );
    149149
    150150        // Create pages.
    151         $this->factory->post->create_many( 10 );
     151        self::$factory->post->create_many( 10 );
    152152
    153153        // Expected menu item array.
     
    176176
    177177        // Create page.
    178         $page_id = $this->factory->post->create( array( 'post_title' => 'Page Title', 'post_type' => 'page' ) );
     178        $page_id = self::$factory->post->create( array( 'post_title' => 'Page Title', 'post_type' => 'page' ) );
    179179
    180180        // Expected menu item array.
     
    202202
    203203        // Create post.
    204         $post_id = $this->factory->post->create( array( 'post_title' => 'Post Title' ) );
     204        $post_id = self::$factory->post->create( array( 'post_title' => 'Post Title' ) );
    205205
    206206        // Expected menu item array.
     
    228228
    229229        // Create term.
    230         $term_id = $this->factory->category->create( array( 'name' => 'Term Title' ) );
     230        $term_id = self::$factory->category->create( array( 'name' => 'Term Title' ) );
    231231
    232232        // Expected menu item array.
     
    280280        // Create posts
    281281        $post_ids = array();
    282         $post_ids[] = $this->factory->post->create( array( 'post_title' => 'Search & Test' ) );
    283         $post_ids[] = $this->factory->post->create( array( 'post_title' => 'Some Other Title' ) );
     282        $post_ids[] = self::$factory->post->create( array( 'post_title' => 'Search & Test' ) );
     283        $post_ids[] = self::$factory->post->create( array( 'post_title' => 'Some Other Title' ) );
    284284
    285285        // Create terms
    286286        $term_ids = array();
    287         $term_ids[] = $this->factory->category->create( array( 'name' => 'Dogs Are Cool' ) );
    288         $term_ids[] = $this->factory->category->create( array( 'name' => 'Cats Drool' ) );
     287        $term_ids[] = self::$factory->category->create( array( 'name' => 'Dogs Are Cool' ) );
     288        $term_ids[] = self::$factory->category->create( array( 'name' => 'Cats Drool' ) );
    289289
    290290        // Test empty results
     
    387387        do_action( 'customize_register', $this->wp_customize );
    388388        $menu_id = wp_create_nav_menu( 'Primary' );
    389         $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
     389        $post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
    390390        $item_id = wp_update_nav_menu_item( $menu_id, 0, array(
    391391            'menu-item-type'      => 'post_type',
Note: See TracChangeset for help on using the changeset viewer.