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

    r32658 r35225  
    129129     */
    130130    function test_check_capabilities() {
    131         $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     131        $user_id = self::$factory->user->create( array( 'role' => 'administrator' ) );
    132132        wp_set_current_user( $user_id );
    133133
     
    155155     */
    156156    function test_maybe_render() {
    157         wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     157        wp_set_current_user( self::$factory->user->create( array( 'role' => 'administrator' ) ) );
    158158        $panel = new WP_Customize_Panel( $this->manager, 'bar' );
    159159        $customize_render_panel_count = did_action( 'customize_render_panel' );
     
    180180     */
    181181    function test_print_templates_standard() {
    182         wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     182        wp_set_current_user( self::$factory->user->create( array( 'role' => 'administrator' ) ) );
    183183
    184184        $panel = new WP_Customize_Panel( $this->manager, 'baz' );
     
    198198     */
    199199    function test_print_templates_custom() {
    200         wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     200        wp_set_current_user( self::$factory->user->create( array( 'role' => 'administrator' ) ) );
    201201
    202202        $panel = new Custom_Panel_Test( $this->manager, 'baz' );
Note: See TracChangeset for help on using the changeset viewer.