WordPress.org

Make WordPress Core


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

    r35186 r35225  
    1616     */
    1717    function test_content_post_type() {
    18         wp_set_current_user( $this->factory->user->create( array( 'role' => 'editor' ) ) );
     18        wp_set_current_user( self::$factory->user->create( array( 'role' => 'editor' ) ) );
    1919
    2020        register_post_type( 'content', array( 'show_in_admin_bar' => true ) );
     
    3535     */
    3636    function test_merging_existing_meta_values() {
    37         wp_set_current_user( $this->factory->user->create( array( 'role' => 'editor' ) ) );
     37        wp_set_current_user( self::$factory->user->create( array( 'role' => 'editor' ) ) );
    3838
    3939        $admin_bar = new WP_Admin_Bar;
     
    6363        }
    6464
    65         $nobody = $this->factory->user->create( array( 'role' => '' ) );
     65        $nobody = self::$factory->user->create( array( 'role' => '' ) );
    6666        $this->assertFalse( user_can( $nobody, 'read' ) );
    6767
     
    9393        }
    9494
    95         $editor = $this->factory->user->create( array( 'role' => 'editor' ) );
     95        $editor = self::$factory->user->create( array( 'role' => 'editor' ) );
    9696        $this->assertTrue( user_can( $editor, 'read' ) );
    9797
     
    126126        }
    127127
    128         $admin  = $this->factory->user->create( array( 'role' => 'administrator' ) );
    129         $editor = $this->factory->user->create( array( 'role' => 'editor' ) );
     128        $admin  = self::$factory->user->create( array( 'role' => 'administrator' ) );
     129        $editor = self::$factory->user->create( array( 'role' => 'editor' ) );
    130130
    131131        $this->assertTrue( user_can( $admin, 'read' ) );
    132132        $this->assertTrue( user_can( $editor, 'read' ) );
    133133
    134         $new_blog_id = $this->factory->blog->create( array(
     134        $new_blog_id = self::$factory->blog->create( array(
    135135            'user_id' => $admin,
    136136        ) );
     
    180180        }
    181181
    182         $admin  = $this->factory->user->create( array( 'role' => 'administrator' ) );
    183         $nobody = $this->factory->user->create( array( 'role' => '' ) );
     182        $admin  = self::$factory->user->create( array( 'role' => 'administrator' ) );
     183        $nobody = self::$factory->user->create( array( 'role' => '' ) );
    184184
    185185        $this->assertTrue( user_can( $admin, 'read' ) );
    186186        $this->assertFalse( user_can( $nobody, 'read' ) );
    187187
    188         $new_blog_id = $this->factory->blog->create( array(
     188        $new_blog_id = self::$factory->blog->create( array(
    189189            'user_id' => $admin,
    190190        ) );
Note: See TracChangeset for help on using the changeset viewer.