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/post/getBodyClass.php

    r31979 r35225  
    1010    public function setUp() {
    1111        parent::setUp();
    12         $this->post_id = $this->factory->post->create();
     12        $this->post_id = self::$factory->post->create();
    1313    }
    1414
     
    1717     */
    1818    public function test_with_utf8_category_slugs() {
    19         $cat_id1 = $this->factory->category->create( array( 'name' => 'Первая рубрика' ) );
    20         $cat_id2 = $this->factory->category->create( array( 'name' => 'Вторая рубрика' ) );
    21         $cat_id3 = $this->factory->category->create( array( 'name' => '25кадр' ) );
     19        $cat_id1 = self::$factory->category->create( array( 'name' => 'Первая рубрика' ) );
     20        $cat_id2 = self::$factory->category->create( array( 'name' => 'Вторая рубрика' ) );
     21        $cat_id3 = self::$factory->category->create( array( 'name' => '25кадр' ) );
    2222        wp_set_post_terms( $this->post_id, array( $cat_id1, $cat_id2, $cat_id3 ), 'category' );
    2323
     
    3636     */
    3737    public function test_with_utf8_tag_slugs() {
    38         $tag_id1 = $this->factory->tag->create( array( 'name' => 'Первая метка' ) );
    39         $tag_id2 = $this->factory->tag->create( array( 'name' => 'Вторая метка' ) );
    40         $tag_id3 = $this->factory->tag->create( array( 'name' => '25кадр' ) );
     38        $tag_id1 = self::$factory->tag->create( array( 'name' => 'Первая метка' ) );
     39        $tag_id2 = self::$factory->tag->create( array( 'name' => 'Вторая метка' ) );
     40        $tag_id3 = self::$factory->tag->create( array( 'name' => '25кадр' ) );
    4141        wp_set_post_terms( $this->post_id, array( $tag_id1, $tag_id2, $tag_id3 ), 'post_tag' );
    4242
     
    6060    public function test_with_utf8_term_slugs() {
    6161        register_taxonomy( 'wptests_tax', 'post' );
    62         $term_id1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Первая метка' ) );
    63         $term_id2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Вторая метка' ) );
    64         $term_id3 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => '25кадр' ) );
     62        $term_id1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Первая метка' ) );
     63        $term_id2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Вторая метка' ) );
     64        $term_id3 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => '25кадр' ) );
    6565        wp_set_post_terms( $this->post_id, array( $term_id1, $term_id2, $term_id3 ), 'wptests_tax' );
    6666
Note: See TracChangeset for help on using the changeset viewer.