Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (11 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/isObjectInTerm.php

    r34812 r35225  
    88        register_taxonomy( 'wptests_tax', 'post' );
    99
    10         $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    11         $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     10        $t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     11        $t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    1212
    13         $posts = $this->factory->post->create_many( 2 );
     13        $posts = self::$factory->post->create_many( 2 );
    1414        wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
    1515
     
    2323        register_taxonomy( 'wptests_tax', 'post' );
    2424
    25         $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    26         $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     25        $t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     26        $t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    2727
    28         $posts = $this->factory->post->create_many( 2 );
     28        $posts = self::$factory->post->create_many( 2 );
    2929        wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
    3030
     
    4141        register_taxonomy( 'wptests_tax', 'post' );
    4242
    43         $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Foo' ) );
    44         $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Bar') );
     43        $t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Foo' ) );
     44        $t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Bar') );
    4545
    46         $posts = $this->factory->post->create_many( 2 );
     46        $posts = self::$factory->post->create_many( 2 );
    4747        wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
    4848
     
    5656        register_taxonomy( 'wptests_tax', 'post' );
    5757
    58         $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
    59         $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
     58        $t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
     59        $t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
    6060
    61         $posts = $this->factory->post->create_many( 2 );
     61        $posts = self::$factory->post->create_many( 2 );
    6262        wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
    6363
     
    7171        register_taxonomy( 'wptests_tax', 'post' );
    7272
    73         $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
    74         $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
     73        $t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
     74        $t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
    7575
    76         $posts = $this->factory->post->create_many( 2 );
     76        $posts = self::$factory->post->create_many( 2 );
    7777        wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
    7878
     
    8888    public function test_should_not_return_true_if_term_name_begins_with_existing_term_id() {
    8989        register_taxonomy( 'wptests_tax', 'post' );
    90         $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     90        $t = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    9191
    92         $post_ID  = $this->factory->post->create();
     92        $post_ID  = self::$factory->post->create();
    9393        wp_set_object_terms( $post_ID, $t, 'wptests_tax' );
    9494
     
    109109
    110110        register_taxonomy( 'wptests_tax', 'post' );
    111         $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     111        $terms = self::$factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
    112112
    113113        $o = 12345;
     
    130130
    131131        register_taxonomy( 'wptests_tax', 'post' );
    132         $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     132        $terms = self::$factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
    133133
    134134        $o = 12345;
Note: See TracChangeset for help on using the changeset viewer.