Make WordPress Core


Ignore:
Timestamp:
10/15/2013 02:30:02 PM (13 years ago)
Author:
nacin
Message:

Test runner: Add @expectedIncorrectUsage to trap _doing_it_wrong() calls.

see #24813, #25282.

File:
1 edited

Legend:

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

    r25408 r25785  
    99        protected $expected_deprecated = array();
    1010        protected $caught_deprecated = array();
     11        protected $expected_doing_it_wrong = array();
     12        protected $caught_doing_it_wrong = array();
    1113
    1214        /**
    … …  
    9092                        if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) )
    9193                                $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] );
     94                        if ( ! empty( $annotations[ $depth ]['expectedIncorrectUsage'] ) )
     95                                $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $annotations[ $depth ]['expectedIncorrectUsage'] );
    9296                }
    9397                add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    9498                add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) );
     99                add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
    95100                add_action( 'deprecated_function_trigger_error', '__return_false' );
    96101                add_action( 'deprecated_argument_trigger_error', '__return_false' );
     102                add_action( 'doing_it_wrong_trigger_error',      '__return_false' );
    97103        }
    98104
    … …  
    107113                        $this->fail( "Unexpected deprecated notice for $unexpected" );
    108114                }
     115
     116                $not_caught_doing_it_wrong = array_diff( $this->expected_doing_it_wrong, $this->caught_doing_it_wrong );
     117                foreach ( $not_caught_doing_it_wrong as $not_caught ) {
     118                        $this->fail( "Failed to assert that $not_caught triggered an incorrect usage notice" );
     119                }
     120
     121                $unexpected_doing_it_wrong = array_diff( $this->caught_doing_it_wrong, $this->expected_doing_it_wrong );
     122                foreach ( $unexpected_doing_it_wrong as $unexpected ) {
     123                        $this->fail( "Unexpected incorrect usage notice for $unexpected" );
     124                }
    109125        }
    110126
    … …  
    112128                if ( ! in_array( $function, $this->caught_deprecated ) )
    113129                        $this->caught_deprecated[] = $function;
     130        }
     131
     132        function doing_it_wrong_run( $function ) {
     133                if ( ! in_array( $function, $this->caught_doing_it_wrong ) )
     134                        $this->caught_doing_it_wrong[] = $function;
    114135        }
    115136
Note: See TracChangeset for help on using the changeset viewer.