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

    r34810 r35225  
    1313
    1414    public function test_integer_should_be_interpreted_as_term_id() {
    15         $t1 = $this->factory->term->create( array(
     15        $t1 = self::$factory->term->create( array(
    1616            'taxonomy' => 'wptests_tax',
    1717            'name' => 'foo',
    1818        ) );
    19         $t2 = $this->factory->term->create( array(
     19        $t2 = self::$factory->term->create( array(
    2020            'taxonomy' => 'wptests_tax',
    2121            'slug' => $t1,
     
    2929
    3030    public function test_numeric_string_should_be_interpreted_as_term_slug() {
    31         $t1 = $this->factory->term->create( array(
     31        $t1 = self::$factory->term->create( array(
    3232            'taxonomy' => 'wptests_tax',
    3333            'name' => 'foo',
    3434        ) );
    35         $t2 = $this->factory->term->create( array(
     35        $t2 = self::$factory->term->create( array(
    3636            'taxonomy' => 'wptests_tax',
    3737            'slug' => $t1,
     
    5050
    5151    public function test_category_should_use_cat_query_var_with_term_id() {
    52         $c = $this->factory->category->create();
     52        $c = self::$factory->category->create();
    5353
    5454        $actual = get_term_link( $c, 'category' );
     
    6161        ) );
    6262
    63         $t = $this->factory->term->create( array(
     63        $t = self::$factory->term->create( array(
    6464            'taxonomy' => 'wptests_tax2',
    6565            'slug' => 'bar',
     
    7575        ) );
    7676
    77         $t = $this->factory->term->create( array(
     77        $t = self::$factory->term->create( array(
    7878            'taxonomy' => 'wptests_tax2',
    7979            'slug' => 'bar',
     
    9898        flush_rewrite_rules();
    9999
    100         $t1 = $this->factory->term->create( array(
     100        $t1 = self::$factory->term->create( array(
    101101            'taxonomy' => 'wptests_tax2',
    102102            'slug' => 'term1',
    103103        ) );
    104104
    105         $t2 = $this->factory->term->create( array(
     105        $t2 = self::$factory->term->create( array(
    106106            'taxonomy' => 'wptests_tax2',
    107107            'slug' => 'term2',
     
    127127        flush_rewrite_rules();
    128128
    129         $t1 = $this->factory->term->create( array(
     129        $t1 = self::$factory->term->create( array(
    130130            'taxonomy' => 'wptests_tax2',
    131131            'slug' => 'term1',
    132132        ) );
    133133
    134         $t2 = $this->factory->term->create( array(
     134        $t2 = self::$factory->term->create( array(
    135135            'taxonomy' => 'wptests_tax2',
    136136            'slug' => 'term2',
Note: See TracChangeset for help on using the changeset viewer.