Make WordPress Core


Ignore:
Timestamp:
02/17/2015 04:11:09 PM (12 years ago)
Author:
boonebgorges
Message:

Improved handling of expectedDeprecated and expectedIncorrectUsage annotations in unit tests.

  • Do the expectedDeprecated() check in assertPostConditions() instead of tearDown(). Previously, failing inside of tearDown() was causing the rest of the teardown process to be aborted, resulting in inter-test leakage.
  • Collect all expectedDeprecated and expectedIncorrectUsage annotations in an entire method and display them all when failing, instead of showing only the first one.

Props jdgrimes.
Fixes #31362.

File:
1 edited

Legend:

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

    r31306 r31469  
    5656        }
    5757
     58        /**
     59         * Detect post-test failure conditions.
     60         *
     61         * We use this method to detect expectedDeprecated and expectedIncorrectUsage annotations.
     62         *
     63         * @since 4.2.0
     64         */
     65        protected function assertPostConditions() {
     66                $this->expectedDeprecated();
     67        }
     68
    5869        function tearDown() {
    5970                global $wpdb, $wp_query, $post;
    60                 $this->expectedDeprecated();
    6171                $wpdb->query( 'ROLLBACK' );
    6272                if ( is_multisite() ) {
    … …  
    225235
    226236        function expectedDeprecated() {
     237                $errors = array();
     238
    227239                $not_caught_deprecated = array_diff( $this->expected_deprecated, $this->caught_deprecated );
    228240                foreach ( $not_caught_deprecated as $not_caught ) {
    229                         $this->fail( "Failed to assert that $not_caught triggered a deprecated notice" );
     241                        $errors[] = "Failed to assert that $not_caught triggered a deprecated notice";
    230242                }
    231243
    232244                $unexpected_deprecated = array_diff( $this->caught_deprecated, $this->expected_deprecated );
    233245                foreach ( $unexpected_deprecated as $unexpected ) {
    234                         $this->fail( "Unexpected deprecated notice for $unexpected" );
     246                        $errors[] = "Unexpected deprecated notice for $unexpected";
    235247                }
    236248
    237249                $not_caught_doing_it_wrong = array_diff( $this->expected_doing_it_wrong, $this->caught_doing_it_wrong );
    238250                foreach ( $not_caught_doing_it_wrong as $not_caught ) {
    239                         $this->fail( "Failed to assert that $not_caught triggered an incorrect usage notice" );
     251                        $errors[] = "Failed to assert that $not_caught triggered an incorrect usage notice";
    240252                }
    241253
    242254                $unexpected_doing_it_wrong = array_diff( $this->caught_doing_it_wrong, $this->expected_doing_it_wrong );
    243255                foreach ( $unexpected_doing_it_wrong as $unexpected ) {
    244                         $this->fail( "Unexpected incorrect usage notice for $unexpected" );
     256                        $errors[] = "Unexpected incorrect usage notice for $unexpected";
     257                }
     258
     259                if ( ! empty( $errors ) ) {
     260                        $this->fail( implode( "\n", $errors ) );
    245261                }
    246262        }
Note: See TracChangeset for help on using the changeset viewer.