Make WordPress Core


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

    r31140 r35225  
    66     */
    77    public function test_category_exists_should_return_only_top_level_categories_when_parent_is_0() {
    8         $c1 = $this->factory->category->create();
    9         $c2 = $this->factory->category->create( array(
     8        $c1 = self::$factory->category->create();
     9        $c2 = self::$factory->category->create( array(
    1010            'name' => 'Foo',
    1111            'parent' => $c1,
    1212        ) );
    13         $c3 = $this->factory->category->create( array(
     13        $c3 = self::$factory->category->create( array(
    1414            'name' => 'Foo',
    1515        ) );
     
    2525    public function test_category_exists_should_select_oldest_matching_category_when_no_parent_is_specified_1() {
    2626        // Foo child of c1 is created first.
    27         $c1 = $this->factory->category->create();
    28         $c2 = $this->factory->category->create( array(
     27        $c1 = self::$factory->category->create();
     28        $c2 = self::$factory->category->create( array(
    2929            'name' => 'Foo',
    3030            'parent' => $c1,
    3131        ) );
    32         $c3 = $this->factory->category->create( array(
     32        $c3 = self::$factory->category->create( array(
    3333            'name' => 'Foo',
    3434        ) );
     
    4444    public function test_category_exists_should_select_oldest_matching_category_when_no_parent_is_specified_2() {
    4545        // Top-level Foo is created first.
    46         $c1 = $this->factory->category->create();
    47         $c2 = $this->factory->category->create( array(
     46        $c1 = self::$factory->category->create();
     47        $c2 = self::$factory->category->create( array(
    4848            'name' => 'Foo',
    4949        ) );
    50         $c3 = $this->factory->category->create( array(
     50        $c3 = self::$factory->category->create( array(
    5151            'name' => 'Foo',
    5252            'parent' => $c1,
     
    6262     */
    6363    public function test_category_exists_should_respect_nonempty_parent() {
    64         $c1 = $this->factory->category->create();
    65         $c2 = $this->factory->category->create( array(
     64        $c1 = self::$factory->category->create();
     65        $c2 = self::$factory->category->create( array(
    6666            'name' => 'Foo',
    6767            'parent' => $c1,
    6868        ) );
    69         $c3 = $this->factory->category->create( array(
     69        $c3 = self::$factory->category->create( array(
    7070            'name' => 'Foo',
    7171        ) );
Note: See TracChangeset for help on using the changeset viewer.