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/tests/comment/template.php

    r28558 r35225  
    66
    77    function test_get_comments_number() {
    8         $post_id = $this->factory->post->create();
     8        $post_id = self::$factory->post->create();
    99
    1010        $this->assertEquals( 0, get_comments_number( 0 ) );
     
    1212        $this->assertEquals( 0, get_comments_number( get_post( $post_id ) ) );
    1313
    14         $this->factory->comment->create_post_comments( $post_id, 12 );
     14        self::$factory->comment->create_post_comments( $post_id, 12 );
    1515
    1616        $this->assertEquals( 12, get_comments_number( $post_id ) );
     
    1919
    2020    function test_get_comments_number_without_arg() {
    21         $post_id = $this->factory->post->create();
     21        $post_id = self::$factory->post->create();
    2222        $permalink = get_permalink( $post_id );
    2323        $this->go_to( $permalink );
     
    2525        $this->assertEquals( 0, get_comments_number() );
    2626
    27         $this->factory->comment->create_post_comments( $post_id, 12 );
     27        self::$factory->comment->create_post_comments( $post_id, 12 );
    2828        $this->go_to( $permalink );
    2929
Note: See TracChangeset for help on using the changeset viewer.