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/term.php

    r35186 r35225  
    2424        ) );
    2525
    26         $parent = $this->factory->term->create( array(
    27             'taxonomy' => 'wptests_tax',
    28         ) );
    29 
    30         $child = $this->factory->term->create( array(
     26        $parent = self::$factory->term->create( array(
     27            'taxonomy' => 'wptests_tax',
     28        ) );
     29
     30        $child = self::$factory->term->create( array(
    3131            'taxonomy' => 'wptests_tax',
    3232            'parent' => $parent,
     
    227227        register_taxonomy( 'wptests_tax', 'post' );
    228228        $p = self::$post_ids[0];
    229         $t1 = $this->factory->term->create( array(
    230             'taxonomy' => 'wptests_tax',
    231         ) );
    232         $t2 = $this->factory->term->create( array(
     229        $t1 = self::$factory->term->create( array(
     230            'taxonomy' => 'wptests_tax',
     231        ) );
     232        $t2 = self::$factory->term->create( array(
    233233            'taxonomy' => 'wptests_tax',
    234234        ) );
     
    248248        register_taxonomy( 'wptests_tax', 'post' );
    249249        $p = self::$post_ids[0];
    250         $t1 = $this->factory->term->create( array(
    251             'taxonomy' => 'wptests_tax',
    252         ) );
    253         $t2 = $this->factory->term->create( array(
     250        $t1 = self::$factory->term->create( array(
     251            'taxonomy' => 'wptests_tax',
     252        ) );
     253        $t2 = self::$factory->term->create( array(
    254254            'taxonomy' => 'wptests_tax',
    255255        ) );
     
    269269        register_taxonomy( 'wptests_tax', 'post' );
    270270        $p = self::$post_ids[0];
    271         $t1 = $this->factory->term->create( array(
    272             'taxonomy' => 'wptests_tax',
    273         ) );
    274         $t2 = $this->factory->term->create( array(
     271        $t1 = self::$factory->term->create( array(
     272            'taxonomy' => 'wptests_tax',
     273        ) );
     274        $t2 = self::$factory->term->create( array(
    275275            'taxonomy' => 'wptests_tax',
    276276        ) );
     
    365365    function test_wp_add_remove_object_terms() {
    366366        $posts = self::$post_ids;
    367         $tags = $this->factory->tag->create_many( 5 );
     367        $tags = self::$factory->tag->create_many( 5 );
    368368
    369369        $tt = wp_add_object_terms( $posts[0], $tags[1], 'post_tag' );
     
    524524    function test_object_term_cache_when_term_changes() {
    525525        $post_id = self::$post_ids[0];
    526         $tag_id = $this->factory->tag->create( array(
     526        $tag_id = self::$factory->tag->create( array(
    527527            'name' => 'Amaze Tag',
    528528            'description' => 'My Amazing Tag'
     
    554554        $p = self::$post_ids[0];
    555555        register_taxonomy( 'wptests_tax', 'post' );
    556         $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     556        $t = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    557557        wp_set_object_terms( $p, $t, 'wptests_tax' );
    558558
     
    573573        $p = self::$post_ids[0];
    574574        register_taxonomy( 'wptests_tax', 'post' );
    575         $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     575        $t = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    576576        wp_set_object_terms( $p, $t, 'wptests_tax' );
    577577
     
    619619     */
    620620    function test_orphan_category() {
    621         $cat_id1 = $this->factory->category->create();
     621        $cat_id1 = self::$factory->category->create();
    622622
    623623        wp_delete_category( $cat_id1 );
    624624
    625         $cat_id2 = $this->factory->category->create( array( 'parent' => $cat_id1 ) );
     625        $cat_id2 = self::$factory->category->create( array( 'parent' => $cat_id1 ) );
    626626        $this->assertWPError( $cat_id2 );
    627627    }
Note: See TracChangeset for help on using the changeset viewer.