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/customize/manager.php

    r34269 r35225  
    252252     */
    253253    function test_return_url() {
    254         wp_set_current_user( $this->factory->user->create( array( 'role' => 'author' ) ) );
     254        wp_set_current_user( self::$factory->user->create( array( 'role' => 'author' ) ) );
    255255        $this->assertEquals( get_admin_url(), $this->manager->get_return_url() );
    256256
    257         wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     257        wp_set_current_user( self::$factory->user->create( array( 'role' => 'administrator' ) ) );
    258258        $this->assertTrue( current_user_can( 'edit_theme_options' ) );
    259259        $this->assertEquals( admin_url( 'themes.php' ), $this->manager->get_return_url() );
     
    302302     */
    303303    function test_customize_pane_settings() {
    304         wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     304        wp_set_current_user( self::$factory->user->create( array( 'role' => 'administrator' ) ) );
    305305        $this->manager->register_controls();
    306306        $this->manager->prepare_controls();
Note: See TracChangeset for help on using the changeset viewer.