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/includes/testcase.php

    r35186 r35225  
    1818     * @var WP_UnitTest_Factory
    1919     */
    20     protected $factory;
    21 
    22     protected static $static_factory;
     20    protected static $factory;
    2321
    2422    public static function get_called_class() {
     
    4038        parent::setUpBeforeClass();
    4139
     40        if ( ! self::$factory ) {
     41            self::$factory = new WP_UnitTest_Factory();
     42        }
     43
    4244        $c = self::get_called_class();
    4345        if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) {
     
    4547        }
    4648
    47         if ( ! self::$static_factory ) {
    48             self::$static_factory = new WP_UnitTest_Factory();
    49         }
    50 
    51         call_user_func( array( $c, 'wpSetUpBeforeClass' ), self::$static_factory );
     49        call_user_func( array( $c, 'wpSetUpBeforeClass' ), self::$factory );
    5250
    5351        self::commit_transaction();
     
    8381        $wpdb->db_connect();
    8482        ini_set('display_errors', 1 );
    85         $this->factory = new WP_UnitTest_Factory;
    8683        $this->clean_up_global_scope();
    8784
Note: See TracChangeset for help on using the changeset viewer.