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

    r33425 r35225  
    8888        $this->assertEquals( $url, $url2 );
    8989
    90         $post_id = $this->factory->post->create( array( 'post_author' => 1 ) );
     90        $post_id = self::$factory->post->create( array( 'post_author' => 1 ) );
    9191        $post = get_post( $post_id );
    9292        $url2 = get_avatar_url( $post );
    9393        $this->assertEquals( $url, $url2 );
    9494
    95         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id, 'user_id' => 1 ) );
     95        $comment_id = self::$factory->comment->create( array( 'comment_post_ID' => $post_id, 'user_id' => 1 ) );
    9696        $comment = get_comment( $comment_id );
    9797        $url2 = get_avatar_url( $comment );
     
    139139        $url = get_avatar_url( 1 );
    140140
    141         $post_id = $this->factory->post->create( array( 'post_author' => 1 ) );
    142         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id, 'user_id' => 1, 'comment_type' => 'pingback' ) );
     141        $post_id = self::$factory->post->create( array( 'post_author' => 1 ) );
     142        $comment_id = self::$factory->comment->create( array( 'comment_post_ID' => $post_id, 'user_id' => 1, 'comment_type' => 'pingback' ) );
    143143        $comment = get_comment( $comment_id );
    144144
Note: See TracChangeset for help on using the changeset viewer.