Changeset 25408
- Timestamp:
- 09/12/2013 06:37:00 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r25402 r25408 7 7 8 8 protected static $forced_tickets = array(); 9 protected $deprecated_functions = array(); 9 protected $expected_deprecated = array(); 10 protected $caught_deprecated = array(); 10 11 11 12 /** … … 25 26 $this->clean_up_global_scope(); 26 27 $this->start_transaction(); 28 $this->expectDeprecated(); 27 29 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' ) );31 30 } 32 31 33 32 function tearDown() { 34 33 global $wpdb; 34 $this->expectedDeprecated(); 35 35 $wpdb->query( 'ROLLBACK' ); 36 36 remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) ); 37 37 remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); 38 38 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;51 39 } 52 40 … … 95 83 function wp_die_handler( $message ) { 96 84 throw new WPDieException( $message ); 85 } 86 87 function expectDeprecated() { 88 $annotations = $this->getAnnotations(); 89 foreach ( array( 'class', 'method' ) as $depth ) { 90 if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) 91 $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] ); 92 } 93 add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); 94 add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) ); 95 add_action( 'deprecated_function_trigger_error', '__return_false' ); 96 add_action( 'deprecated_argument_trigger_error', '__return_false' ); 97 } 98 99 function expectedDeprecated() { 100 $not_caught_deprecated = array_diff( $this->expected_deprecated, $this->caught_deprecated ); 101 foreach ( $not_caught_deprecated as $not_caught ) { 102 $this->fail( "Failed to assert that $not_caught triggered a deprecated notice" ); 103 } 104 105 $unexpected_deprecated = array_diff( $this->caught_deprecated, $this->expected_deprecated ); 106 foreach ( $unexpected_deprecated as $unexpected ) { 107 $this->fail( "Unexpected deprecated notice for $unexpected" ); 108 } 109 } 110 111 function deprecated_function_run( $function ) { 112 if ( ! in_array( $function, $this->caught_deprecated ) ) 113 $this->caught_deprecated[] = $function; 97 114 } 98 115
Note: See TracChangeset
for help on using the changeset viewer.