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/rewrite/numericSlugs.php

    r34810 r35225  
    1010    public function setUp() {
    1111        parent::setUp();
    12         $this->author_id = $this->factory->user->create( array( 'role' => 'editor' ) );
     12        $this->author_id = self::$factory->user->create( array( 'role' => 'editor' ) );
    1313
    1414        // Override the post/archive slug collision prevention in `wp_unique_post_slug()`.
     
    2424        $this->set_permalink_structure( '/%postname%/' );
    2525
    26         $id = $this->factory->post->create( array(
     26        $id = self::$factory->post->create( array(
    2727            'post_author'  => $this->author_id,
    2828            'post_status'  => 'publish',
     
    5252        $this->set_permalink_structure( '/%postname%/' );
    5353
    54         $id = $this->factory->post->create( array(
     54        $id = self::$factory->post->create( array(
    5555            'post_author'  => $this->author_id,
    5656            'post_status'  => 'publish',
     
    7777        $this->set_permalink_structure( '/%postname%/' );
    7878
    79         $id = $this->factory->post->create( array(
     79        $id = self::$factory->post->create( array(
    8080            'post_author'  => $this->author_id,
    8181            'post_status'  => 'publish',
     
    9393        $this->set_permalink_structure( '/%postname%/' );
    9494
    95         $id = $this->factory->post->create( array(
     95        $id = self::$factory->post->create( array(
    9696            'post_author'  => $this->author_id,
    9797            'post_status'  => 'publish',
     
    107107        $this->set_permalink_structure( '/%year%/%postname%/' );
    108108
    109         $id = $this->factory->post->create( array(
     109        $id = self::$factory->post->create( array(
    110110            'post_author'  => $this->author_id,
    111111            'post_status'  => 'publish',
     
    124124        $this->set_permalink_structure( '/%year%/%postname%/' );
    125125
    126         $id = $this->factory->post->create( array(
     126        $id = self::$factory->post->create( array(
    127127            'post_author'  => $this->author_id,
    128128            'post_status'  => 'publish',
     
    139139        $this->set_permalink_structure( '/%year%/%postname%/' );
    140140
    141         $id = $this->factory->post->create( array(
     141        $id = self::$factory->post->create( array(
    142142            'post_author'  => $this->author_id,
    143143            'post_status'  => 'publish',
     
    156156        $this->set_permalink_structure( '/%year%/%postname%/' );
    157157
    158         $id = $this->factory->post->create( array(
     158        $id = self::$factory->post->create( array(
    159159            'post_author'  => $this->author_id,
    160160            'post_status'  => 'publish',
     
    171171        $this->set_permalink_structure( '/%year%/%postname%/' );
    172172
    173         $id = $this->factory->post->create( array(
     173        $id = self::$factory->post->create( array(
    174174            'post_author'  => $this->author_id,
    175175            'post_status'  => 'publish',
     
    187187        $this->set_permalink_structure( '/%year%/%postname%/' );
    188188
    189         $id = $this->factory->post->create( array(
     189        $id = self::$factory->post->create( array(
    190190            'post_author'  => $this->author_id,
    191191            'post_status'  => 'publish',
     
    201201        $this->set_permalink_structure( '/%year%/%postname%/' );
    202202
    203         $id = $this->factory->post->create( array(
     203        $id = self::$factory->post->create( array(
    204204            'post_author'  => $this->author_id,
    205205            'post_status'  => 'publish',
     
    217217        $this->set_permalink_structure( '/%year%/%postname%/' );
    218218
    219         $id = $this->factory->post->create( array(
     219        $id = self::$factory->post->create( array(
    220220            'post_author'  => $this->author_id,
    221221            'post_status'  => 'publish',
     
    231231        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    232232
    233         $id = $this->factory->post->create( array(
     233        $id = self::$factory->post->create( array(
    234234            'post_author'  => $this->author_id,
    235235            'post_status'  => 'publish',
     
    248248        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    249249
    250         $id = $this->factory->post->create( array(
     250        $id = self::$factory->post->create( array(
    251251            'post_author'  => $this->author_id,
    252252            'post_status'  => 'publish',
     
    263263        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    264264
    265         $id = $this->factory->post->create( array(
     265        $id = self::$factory->post->create( array(
    266266            'post_author'  => $this->author_id,
    267267            'post_status'  => 'publish',
     
    279279        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    280280
    281         $id = $this->factory->post->create( array(
     281        $id = self::$factory->post->create( array(
    282282            'post_author'  => $this->author_id,
    283283            'post_status'  => 'publish',
     
    293293        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    294294
    295         $id = $this->factory->post->create( array(
     295        $id = self::$factory->post->create( array(
    296296            'post_author'  => $this->author_id,
    297297            'post_status'  => 'publish',
     
    315315
    316316        // Make sure a post is published in 2013/02, to avoid 404s.
    317         $this->factory->post->create( array(
     317        self::$factory->post->create( array(
    318318            'post_author'  => $this->author_id,
    319319            'post_status'  => 'publish',
     
    323323        ) );
    324324
    325         $id = $this->factory->post->create( array(
     325        $id = self::$factory->post->create( array(
    326326            'post_author'  => $this->author_id,
    327327            'post_status'  => 'publish',
     
    343343
    344344        // Make sure a post is published on 2015/01/01, to avoid 404s.
    345         $this->factory->post->create( array(
     345        self::$factory->post->create( array(
    346346            'post_author'  => $this->author_id,
    347347            'post_status'  => 'publish',
     
    351351        ) );
    352352
    353         $id = $this->factory->post->create( array(
     353        $id = self::$factory->post->create( array(
    354354            'post_author'  => $this->author_id,
    355355            'post_status'  => 'publish',
     
    370370        $this->set_permalink_structure( '/%year%/%postname%/' );
    371371
    372         $id = $this->factory->post->create( array(
     372        $id = self::$factory->post->create( array(
    373373            'post_author'  => $this->author_id,
    374374            'post_status'  => 'publish',
     
    386386        $this->set_permalink_structure( '/%year%/%postname%/' );
    387387
    388         $id = $this->factory->post->create( array(
     388        $id = self::$factory->post->create( array(
    389389            'post_author'  => $this->author_id,
    390390            'post_status'  => 'publish',
     
    402402        $this->set_permalink_structure( '/%year%/%postname%/' );
    403403
    404         $id = $this->factory->post->create( array(
     404        $id = self::$factory->post->create( array(
    405405            'post_author'  => $this->author_id,
    406406            'post_status'  => 'publish',
     
    419419        $this->set_permalink_structure( '/%year%/%postname%/' );
    420420
    421         $id = $this->factory->post->create( array(
     421        $id = self::$factory->post->create( array(
    422422            'post_author'  => $this->author_id,
    423423            'post_status'  => 'publish',
Note: See TracChangeset for help on using the changeset viewer.