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/wpUniqueTermSlug.php

    r32507 r35225  
    1212
    1313    public function test_unique_slug_should_be_unchanged() {
    14         $term = $this->factory->term->create_and_get( array(
     14        $term = self::$factory->term->create_and_get( array(
    1515            'taxonomy' => 'wptests_tax1',
    1616            'name' => 'foo',
     
    2323
    2424    public function test_nonunique_slug_in_different_taxonomy_should_be_unchanged() {
    25         $term1 = $this->factory->term->create( array(
     25        $term1 = self::$factory->term->create( array(
    2626            'taxonomy' => 'wptests_tax2',
    2727            'name' => 'bar',
     
    2929        ) );
    3030
    31         $term2 = $this->factory->term->create( array(
     31        $term2 = self::$factory->term->create( array(
    3232            'taxonomy' => 'wptests_tax1',
    3333            'name' => 'foo',
     
    4141
    4242    public function test_nonunique_slug_in_same_nonhierarchical_taxonomy_should_be_changed() {
    43         $term1 = $this->factory->term->create( array(
     43        $term1 = self::$factory->term->create( array(
    4444            'taxonomy' => 'wptests_tax1',
    4545            'name' => 'bar',
     
    4747        ) );
    4848
    49         $term2 = $this->factory->term->create( array(
     49        $term2 = self::$factory->term->create( array(
    5050            'taxonomy' => 'wptests_tax1',
    5151            'name' => 'foo',
     
    5959
    6060    public function test_nonunique_slug_in_same_hierarchical_taxonomy_with_same_parent_should_be_suffixed_with_parent_slug() {
    61         $parent = $this->factory->term->create( array(
     61        $parent = self::$factory->term->create( array(
    6262            'taxonomy' => 'wptests_tax2',
    6363            'slug' => 'parent-term',
    6464        ) );
    6565
    66         $term1 = $this->factory->term->create( array(
     66        $term1 = self::$factory->term->create( array(
    6767            'taxonomy' => 'wptests_tax2',
    6868            'name' => 'bar',
     
    7171        ) );
    7272
    73         $term2 = $this->factory->term->create( array(
     73        $term2 = self::$factory->term->create( array(
    7474            'taxonomy' => 'wptests_tax2',
    7575            'name' => 'foo',
     
    8484
    8585    public function test_nonunique_slug_in_same_hierarchical_taxonomy_at_different_level_of_hierarchy_should_be_suffixed_with_number() {
    86         $parent = $this->factory->term->create( array(
     86        $parent = self::$factory->term->create( array(
    8787            'taxonomy' => 'wptests_tax2',
    8888            'slug' => 'parent-term',
    8989        ) );
    9090
    91         $term1 = $this->factory->term->create( array(
     91        $term1 = self::$factory->term->create( array(
    9292            'taxonomy' => 'wptests_tax2',
    9393            'name' => 'bar',
     
    9696        ) );
    9797
    98         $term2 = $this->factory->term->create( array(
     98        $term2 = self::$factory->term->create( array(
    9999            'taxonomy' => 'wptests_tax2',
    100100            'name' => 'foo',
Note: See TracChangeset for help on using the changeset viewer.