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/user/wpSetCurrentUser.php

    r34947 r35225  
    66class Tests_User_WpSetCurrentUser extends WP_UnitTestCase {
    77    public function test_set_by_id() {
    8         $u = $this->factory->user->create();
     8        $u = self::$factory->user->create();
    99
    1010        $user = wp_set_current_user( $u );
     
    1616
    1717    public function test_name_should_be_ignored_if_id_is_not_null() {
    18         $u = $this->factory->user->create();
     18        $u = self::$factory->user->create();
    1919
    2020        $user = wp_set_current_user( $u, 'foo' );
     
    2626
    2727    public function test_should_set_by_name_if_id_is_null_and_current_user_is_nonempty() {
    28         $u1 = $this->factory->user->create();
     28        $u1 = self::$factory->user->create();
    2929        wp_set_current_user( $u1 );
    3030        $this->assertSame( $u1, get_current_user_id() );
    3131
    32         $u2 = $this->factory->user->create( array(
     32        $u2 = self::$factory->user->create( array(
    3333            'user_login' => 'foo',
    3434        ) );
     
    5050        $this->assertSame( 0, get_current_user_id() );
    5151
    52         $u = $this->factory->user->create( array(
     52        $u = self::$factory->user->create( array(
    5353            'user_login' => 'foo',
    5454        ) );
Note: See TracChangeset for help on using the changeset viewer.