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

    r30702 r35225  
    99    function setUp() {
    1010        parent::setUp();
    11         $this->author = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) );
     11        $this->author = new WP_User( self::$factory->user->create( array( 'role' => 'author' ) ) );
    1212        $this->meta_id = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value' );
    1313        $this->delete_meta_id = add_metadata( 'user', $this->author->ID, 'delete_meta_key', 'delete_meta_value' );
     
    195195     */
    196196    function test_meta_type_cast() {
    197         $post_id1 = $this->factory->post->create();
     197        $post_id1 = self::$factory->post->create();
    198198        add_post_meta( $post_id1, 'num_as_longtext', 123 );
    199199        add_post_meta( $post_id1, 'num_as_longtext_desc', 10 );
    200         $post_id2 = $this->factory->post->create();
     200        $post_id2 = self::$factory->post->create();
    201201        add_post_meta( $post_id2, 'num_as_longtext', 99 );
    202202        add_post_meta( $post_id2, 'num_as_longtext_desc', 100 );
     
    259259
    260260    function test_meta_cache_order_asc() {
    261         $post_id = $this->factory->post->create();
     261        $post_id = self::$factory->post->create();
    262262        $colors = array( 'red', 'blue', 'yellow', 'green' );
    263263        foreach ( $colors as $color )
Note: See TracChangeset for help on using the changeset viewer.