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

    r30031 r35225  
    126126
    127127    public function test_transform_query_resulting_field_sanitized() {
    128         $t1 = $this->factory->category->create( array( 'slug' => 'foo', ) );
    129         $t2 = $this->factory->category->create( array( 'slug' => 'bar', ) );
    130         $p = $this->factory->post->create();
     128        $t1 = self::$factory->category->create( array( 'slug' => 'foo', ) );
     129        $t2 = self::$factory->category->create( array( 'slug' => 'bar', ) );
     130        $p = self::$factory->post->create();
    131131        wp_set_post_categories( $p, $t1 );
    132132
     
    151151
    152152    public function test_transform_query_field_slug() {
    153         $t1 = $this->factory->category->create( array( 'slug' => 'foo', ) );
    154         $p = $this->factory->post->create();
     153        $t1 = self::$factory->category->create( array( 'slug' => 'foo', ) );
     154        $p = self::$factory->post->create();
    155155        $tt_ids = wp_set_post_categories( $p, $t1 );
    156156
     
    169169
    170170    public function test_transform_query_field_name() {
    171         $t1 = $this->factory->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) );
    172         $p = $this->factory->post->create();
     171        $t1 = self::$factory->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) );
     172        $p = self::$factory->post->create();
    173173        $tt_ids = wp_set_post_categories( $p, $t1 );
    174174
     
    187187
    188188    public function test_transform_query_field_term_taxonomy_id() {
    189         $t1 = $this->factory->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) );
    190         $p = $this->factory->post->create();
     189        $t1 = self::$factory->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) );
     190        $p = self::$factory->post->create();
    191191        $tt_ids = wp_set_post_categories( $p, $t1 );
    192192
     
    205205
    206206    public function test_transform_query_field_term_taxonomy_default() {
    207         $t1 = $this->factory->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) );
    208         $p = $this->factory->post->create();
     207        $t1 = self::$factory->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) );
     208        $p = self::$factory->post->create();
    209209        $tt_ids = wp_set_post_categories( $p, $t1 );
    210210
     
    241241        register_taxonomy( 'wptests_tax', 'post' );
    242242
    243         $t1 = $this->factory->term->create( array(
    244             'taxonomy' => 'wptests_tax',
    245         ) );
    246         $t2 = $this->factory->term->create( array(
    247             'taxonomy' => 'wptests_tax',
    248         ) );
    249         $t3 = $this->factory->term->create( array(
     243        $t1 = self::$factory->term->create( array(
     244            'taxonomy' => 'wptests_tax',
     245        ) );
     246        $t2 = self::$factory->term->create( array(
     247            'taxonomy' => 'wptests_tax',
     248        ) );
     249        $t3 = self::$factory->term->create( array(
    250250            'taxonomy' => 'wptests_tax',
    251251        ) );
     
    285285        register_taxonomy( 'wptests_tax', 'post' );
    286286
    287         $t1 = $this->factory->term->create( array(
    288             'taxonomy' => 'wptests_tax',
    289         ) );
    290         $t2 = $this->factory->term->create( array(
    291             'taxonomy' => 'wptests_tax',
    292         ) );
    293         $t3 = $this->factory->term->create( array(
     287        $t1 = self::$factory->term->create( array(
     288            'taxonomy' => 'wptests_tax',
     289        ) );
     290        $t2 = self::$factory->term->create( array(
     291            'taxonomy' => 'wptests_tax',
     292        ) );
     293        $t3 = self::$factory->term->create( array(
    294294            'taxonomy' => 'wptests_tax',
    295295        ) );
     
    328328        register_taxonomy( 'wptests_tax', 'post' );
    329329
    330         $t1 = $this->factory->term->create( array(
    331             'taxonomy' => 'wptests_tax',
    332         ) );
    333         $t2 = $this->factory->term->create( array(
    334             'taxonomy' => 'wptests_tax',
    335         ) );
    336         $t3 = $this->factory->term->create( array(
     330        $t1 = self::$factory->term->create( array(
     331            'taxonomy' => 'wptests_tax',
     332        ) );
     333        $t2 = self::$factory->term->create( array(
     334            'taxonomy' => 'wptests_tax',
     335        ) );
     336        $t3 = self::$factory->term->create( array(
    337337            'taxonomy' => 'wptests_tax',
    338338        ) );
Note: See TracChangeset for help on using the changeset viewer.