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.



git-svn-id: https://develop.svn.wordpress.org/trunk@25402 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2013-09-12 14:47:58 +00:00
parent 1851da1382
commit 654d07ebf9
10 changed files with 32 additions and 148 deletions

View File

@@ -6,6 +6,7 @@ require_once dirname( __FILE__ ) . '/trac.php';
class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
protected static $forced_tickets = array();
protected $deprecated_functions = array();
/**
* @var WP_UnitTest_Factory
@@ -24,6 +25,9 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
$this->clean_up_global_scope();
$this->start_transaction();
add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
if ( ! empty( $this->deprecated_functions ) )
add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
}
function tearDown() {
@@ -32,6 +36,18 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
if ( ! empty( $this->deprecated_functions ) )
remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
}
function deprecated_function_run( $function ) {
if ( in_array( $function, $this->deprecated_functions ) )
add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
}
function deprecated_function_trigger_error() {
remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) );
return false;
}
function clean_up_global_scope() {