Make WordPress Core


Ignore:
Timestamp:
09/12/2013 02:47:58 PM (13 years ago)
Author:
wonderboymusic
Message:

There was way too much duplicated code in my notice cleanup, it built up over time, and there's definitely a need to standardize.

  • Remove duplicated code for deprecated function notice suppression
  • Add support in WP_UnitTestCase setUp/tearDown methods for $deprecated_functions fixture if the extending class has added it
  • Add a $deprecated_functions fixture to each extending class that needs it

To use this fixture, add something to your Test Case class like so:
protected $deprecated_functions = array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' );

See #25282.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r25017 r25402  
    77
    88        protected static $forced_tickets = array();
     9        protected $deprecated_functions = array();
    910
    1011        /**
    … …  
    2526                $this->start_transaction();
    2627                add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     28
     29                if ( ! empty( $this->deprecated_functions ) )
     30                        add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    2731        }
    2832
    … …  
    3337                remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
    3438                remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     39                if ( ! empty( $this->deprecated_functions ) )
     40                        remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
     41        }
     42
     43        function deprecated_function_run( $function ) {
     44                if ( in_array( $function, $this->deprecated_functions ) )
     45                        add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
     46        }
     47
     48        function deprecated_function_trigger_error() {
     49                remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
     50                return false;
    3551        }
    3652
Note: See TracChangeset for help on using the changeset viewer.