Make WordPress Core


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

    r34561 r35225  
    3939    function test_empty() {
    4040        //setup post and comments
    41         $post_id = $this->factory->post->create( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
     41        $post_id = self::$factory->post->create( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
    4242        $this->go_to( '/?p=' . $post_id );
    4343
     
    6161    function test_threaded_comments( ) {
    6262        //setup post and comments
    63         $post = $this->factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
    64         $comments = $this->factory->comment->create_post_comments( $post->ID, 15 );
    65         $this->factory->comment->create_post_comments( $post->ID, 6, array( 'comment_parent' => $comments[0] ) );
     63        $post = self::$factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
     64        $comments = self::$factory->comment->create_post_comments( $post->ID, 15 );
     65        self::$factory->comment->create_post_comments( $post->ID, 6, array( 'comment_parent' => $comments[0] ) );
    6666        $comments = get_comments( array( 'post_id' => $post->ID ) );
    6767
     
    7777
    7878        //setup post and comments
    79         $post = $this->factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
    80         $comments = $this->factory->comment->create_post_comments( $post->ID, 15 );
    81         $this->factory->comment->create_post_comments( $post->ID, 6, array('comment_parent' => $comments[0] ) );
     79        $post = self::$factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
     80        $comments = self::$factory->comment->create_post_comments( $post->ID, 15 );
     81        self::$factory->comment->create_post_comments( $post->ID, 6, array('comment_parent' => $comments[0] ) );
    8282        $comments = get_comments( array( 'post_id' => $post->ID ) );
    8383
     
    105105        update_option( 'posts_per_rss', 100 );
    106106
    107         $post = $this->factory->post->create_and_get( array( 'post_title' => 'comment-post', 'post_type' => 'post' ) );
    108         $comments = $this->factory->comment->create_post_comments( $post->ID, 25 );
     107        $post = self::$factory->post->create_and_get( array( 'post_title' => 'comment-post', 'post_type' => 'post' ) );
     108        $comments = self::$factory->comment->create_post_comments( $post->ID, 25 );
    109109
    110110        $wp_query = new WP_Query( array( 'p' => $post->ID, 'comments_per_page' => 10, 'feed' =>'comments-' ) );
Note: See TracChangeset for help on using the changeset viewer.