WordPress.org

Make WordPress Core


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

    r34711 r35225  
    1111        global $wpdb;
    1212
    13         $p = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    14         $comment_ids = $this->factory->comment->create_post_comments( $p, 3 );
     13        $p = self::$factory->post->create( array( 'post_status' => 'publish' ) );
     14        $comment_ids = self::$factory->comment->create_post_comments( $p, 3 );
    1515
    1616        foreach ( $comment_ids as $cid ) {
     
    3939        global $wpdb;
    4040
    41         $p = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    42         $comment_ids = $this->factory->comment->create_post_comments( $p, 3 );
     41        $p = self::$factory->post->create( array( 'post_status' => 'publish' ) );
     42        $comment_ids = self::$factory->comment->create_post_comments( $p, 3 );
    4343
    4444        foreach ( $comment_ids as $cid ) {
     
    6868        global $wpdb;
    6969
    70         $p = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    71         $comment_ids = $this->factory->comment->create_post_comments( $p, 3 );
     70        $p = self::$factory->post->create( array( 'post_status' => 'publish' ) );
     71        $comment_ids = self::$factory->comment->create_post_comments( $p, 3 );
    7272
    7373        foreach ( $comment_ids as $cid ) {
     
    9494        global $wpdb;
    9595
    96         $p = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    97         $comment_ids = $this->factory->comment->create_post_comments( $p, 3 );
     96        $p = self::$factory->post->create( array( 'post_status' => 'publish' ) );
     97        $comment_ids = self::$factory->comment->create_post_comments( $p, 3 );
    9898
    9999        foreach ( $comment_ids as $cid ) {
     
    129129        global $wpdb;
    130130
    131         $posts = $this->factory->post->create_many( 2, array( 'post_status' => 'publish' ) );
     131        $posts = self::$factory->post->create_many( 2, array( 'post_status' => 'publish' ) );
    132132
    133133        $now = time();
    134134        $comments = array();
    135135        for ( $i = 0; $i < 5; $i++ ) {
    136             $comments[] = $this->factory->comment->create( array(
     136            $comments[] = self::$factory->comment->create( array(
    137137                'comment_post_ID' => $posts[0],
    138138                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( 60 * $i ) ),
     
    173173        global $wpdb;
    174174
    175         $posts = $this->factory->post->create_many( 2, array( 'post_status' => 'publish' ) );
     175        $posts = self::$factory->post->create_many( 2, array( 'post_status' => 'publish' ) );
    176176
    177177        $now = time();
    178178        $comments = array();
    179179        for ( $i = 0; $i < 5; $i++ ) {
    180             $comments[] = $this->factory->comment->create( array(
     180            $comments[] = self::$factory->comment->create( array(
    181181                'comment_post_ID' => $posts[0],
    182182                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( 60 * $i ) ),
Note: See TracChangeset for help on using the changeset viewer.