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-menu-item-setting.php

    r33366 r35225  
    2222        parent::setUp();
    2323        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    24         wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     24        wp_set_current_user( self::$factory->user->create( array( 'role' => 'administrator' ) ) );
    2525
    2626        global $wp_customize;
     
    150150        do_action( 'customize_register', $this->wp_customize );
    151151
    152         $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
     152        $post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
    153153
    154154        $menu_id = wp_create_nav_menu( 'Menu' );
     
    193193        do_action( 'customize_register', $this->wp_customize );
    194194
    195         $tax_id = $this->factory->category->create( array( 'name' => 'Salutations' ) );
     195        $tax_id = self::$factory->category->create( array( 'name' => 'Salutations' ) );
    196196
    197197        $menu_id = wp_create_nav_menu( 'Menu' );
     
    271271        $this->assertEquals( $post_value, $value );
    272272
    273         $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
     273        $post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
    274274        $item_id = wp_update_nav_menu_item( $menu_id, 0, array(
    275275            'menu-item-type' => 'post_type',
     
    297297        do_action( 'customize_register', $this->wp_customize );
    298298
    299         $first_post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
    300         $second_post_id = $this->factory->post->create( array( 'post_title' => 'Hola Muno' ) );
     299        $first_post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
     300        $second_post_id = self::$factory->post->create( array( 'post_title' => 'Hola Muno' ) );
    301301
    302302        $primary_menu_id = wp_create_nav_menu( 'Primary' );
     
    349349
    350350        $menu_id = wp_create_nav_menu( 'Primary' );
    351         $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
     351        $post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
    352352        $item_ids = array();
    353353        for ( $i = 0; $i < 5; $i += 1 ) {
     
    404404
    405405        $menu_id = wp_create_nav_menu( 'Primary' );
    406         $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
     406        $post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
    407407        $item_ids = array();
    408408        for ( $i = 0; $i < 5; $i += 1 ) {
     
    489489        do_action( 'customize_register', $this->wp_customize );
    490490
    491         $first_post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
    492         $second_post_id = $this->factory->post->create( array( 'post_title' => 'Hola Muno' ) );
     491        $first_post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
     492        $second_post_id = self::$factory->post->create( array( 'post_title' => 'Hola Muno' ) );
    493493
    494494        $primary_menu_id = wp_create_nav_menu( 'Primary' );
     
    555555
    556556        $menu_id = wp_create_nav_menu( 'Primary' );
    557         $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
     557        $post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
    558558        $item_ids = array();
    559559        for ( $i = 0; $i < 5; $i += 1 ) {
     
    624624
    625625        $menu_id = wp_create_nav_menu( 'Primary' );
    626         $post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
     626        $post_id = self::$factory->post->create( array( 'post_title' => 'Hello World' ) );
    627627        $item_ids = array();
    628628        for ( $i = 0; $i < 5; $i += 1 ) {
Note: See TracChangeset for help on using the changeset viewer.