Make WordPress Core


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

    r34915 r35225  
    1818
    1919    function test_request_json() {
    20         $user = $this->factory->user->create_and_get( array(
    21             'display_name' => 'John Doe',
    22         ) );
    23         $post = $this->factory->post->create_and_get( array(
     20        $user = self::$factory->user->create_and_get( array(
     21            'display_name' => 'John Doe',
     22        ) );
     23        $post = self::$factory->post->create_and_get( array(
    2424            'post_author' => $user->ID,
    2525            'post_title'  => 'Hello World',
     
    6161
    6262    function test_request_jsonp() {
    63         $user = $this->factory->user->create_and_get( array(
    64             'display_name' => 'John Doe',
    65         ) );
    66         $post = $this->factory->post->create_and_get( array(
     63        $user = self::$factory->user->create_and_get( array(
     64            'display_name' => 'John Doe',
     65        ) );
     66        $post = self::$factory->post->create_and_get( array(
    6767            'post_author' => $user->ID,
    6868            'post_title'  => 'Hello World',
     
    8484
    8585    function test_request_jsonp_invalid_callback() {
    86         $user = $this->factory->user->create_and_get( array(
    87             'display_name' => 'John Doe',
    88         ) );
    89         $post = $this->factory->post->create_and_get( array(
     86        $user = self::$factory->user->create_and_get( array(
     87            'display_name' => 'John Doe',
     88        ) );
     89        $post = self::$factory->post->create_and_get( array(
    9090            'post_author' => $user->ID,
    9191            'post_title'  => 'Hello World',
     
    119119
    120120    function test_request_xml() {
    121         $user = $this->factory->user->create_and_get( array(
    122             'display_name' => 'John Doe',
    123         ) );
    124         $post = $this->factory->post->create_and_get( array(
     121        $user = self::$factory->user->create_and_get( array(
     122            'display_name' => 'John Doe',
     123        ) );
     124        $post = self::$factory->post->create_and_get( array(
    125125            'post_author' => $user->ID,
    126126            'post_title'  => 'Hello World',
     
    178178        }
    179179
    180         $child = $this->factory->blog->create();
     180        $child = self::$factory->blog->create();
    181181
    182182        switch_to_blog( $child );
    183183
    184         $post = $this->factory->post->create_and_get( array(
     184        $post = self::$factory->post->create_and_get( array(
    185185            'post_title' => 'Hello Child Blog',
    186186        ) );
     
    208208        $this->assertEquals( home_url() . '/?oembed=true', get_oembed_endpoint_url( '', 'xml' ) );
    209209
    210         $post_id     = $this->factory->post->create();
     210        $post_id     = self::$factory->post->create();
    211211        $url         = get_permalink( $post_id );
    212212        $url_encoded = urlencode( $url );
Note: See TracChangeset for help on using the changeset viewer.