Make WordPress Core


Ignore:
Timestamp:
10/17/2015 06:02:16 PM (9 years ago)
Author:
wonderboymusic
Message:

Unit Tests: after [35225], make factory a method/getter on WP_UnitTestCase and add magic methods for BC for every plugin that is extending WP_UnitTestCase and accessing the $factory instance prop.

Props nerrad, wonderboymusic.
See #30017, #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r35225 r35242  
    1515    protected static $ignore_files;
    1616
    17     /**
    18      * @var WP_UnitTest_Factory
    19      */
    20     protected static $factory;
     17    function __isset( $name ) {
     18        return 'factory' === $name;
     19    }
     20
     21    function __get( $name ) {
     22        if ( 'factory' === $name ) {
     23            return self::factory();
     24        }
     25    }
     26
     27    protected static function factory() {
     28        static $factory = null;
     29        if ( ! $factory ) {
     30            $factory = new WP_UnitTest_Factory();
     31        }
     32        return $factory;
     33    }
    2134
    2235    public static function get_called_class() {
     
    3851        parent::setUpBeforeClass();
    3952
    40         if ( ! self::$factory ) {
    41             self::$factory = new WP_UnitTest_Factory();
    42         }
    43 
    4453        $c = self::get_called_class();
    4554        if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) {
     
    4756        }
    4857
    49         call_user_func( array( $c, 'wpSetUpBeforeClass' ), self::$factory );
     58        call_user_func( array( $c, 'wpSetUpBeforeClass' ), self::factory() );
    5059
    5160        self::commit_transaction();
Note: See TracChangeset for help on using the changeset viewer.