Make WordPress Core

Changeset 31622


Ignore:
Timestamp:
03/05/2015 01:14:15 PM (10 years ago)
Author:
boonebgorges
Message:

In PHPUnit test classes, parent::tearDown() should be the last thing done in tearDown() methods.

WP_UnitTestCase::tearDown() restores the test environment to the default
conditions, including rolling back the MySQL transaction that the test takes
place in, resetting globals, and unhooking test-specific filters. As such, all
teardown routines for specific tests should happen before the parent class's
tearDown() method is called. Failure to do so can cause database locks on
certain configurations, among other problems.

See #31537.

Location:
trunk/tests/phpunit/tests
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesScreen.php

    r26456 r31622  
    3838
    3939    function tearDown() {
    40         parent::tearDown();
    4140        unset( $GLOBALS['wp_taxonomies']['old-or-new'] );
    4241        set_current_screen( 'front' );
     42        parent::tearDown();
    4343    }
    4444
  • trunk/tests/phpunit/tests/ajax/Autosave.php

    r26995 r31622  
    4747     */
    4848    public function tearDown() {
     49        wp_set_current_user( 0 );
    4950        parent::tearDown();
    50         wp_set_current_user( 0 );
    5151    }
    5252
  • trunk/tests/phpunit/tests/ajax/ReplytoComment.php

    r31277 r31622  
    4444
    4545    public function tearDown() {
     46        remove_filter( 'query', array( $this, '_block_comments' ) );
    4647        parent::tearDown();
    47         remove_filter( 'query', array( $this, '_block_comments' ) );
    4848    }
    4949
  • trunk/tests/phpunit/tests/ajax/Response.php

    r25002 r31622  
    3737     */
    3838    public function tearDown() {
    39         parent::tearDown();
    4039        remove_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
    4140        error_reporting( $this->_error_level );
     41        parent::tearDown();
    4242    }
    4343
  • trunk/tests/phpunit/tests/basic.php

    r28631 r31622  
    1414
    1515    function tearDown() {
     16        $this->val = false;
    1617        parent::tearDown();
    17         $this->val = false;
    1818    }
    1919
  • trunk/tests/phpunit/tests/cache.php

    r25002 r31622  
    1515
    1616    function tearDown() {
     17        $this->flush_cache();
    1718        parent::tearDown();
    18         $this->flush_cache();
    1919    }
    2020
  • trunk/tests/phpunit/tests/canonical.php

    r30282 r31622  
    2424
    2525    public function tearDown() {
     26        wp_set_current_user( self::$old_current_user );
    2627        parent::tearDown();
    27         wp_set_current_user( self::$old_current_user );
    2828    }
    2929
  • trunk/tests/phpunit/tests/canonical/pageOnFront.php

    r30277 r31622  
    2727    function tearDown() {
    2828        global $wp_rewrite;
     29        $wp_rewrite->init();
    2930        parent::tearDown();
    30         $wp_rewrite->init();
    3131    }
    3232
  • trunk/tests/phpunit/tests/category.php

    r31006 r31622  
    1111
    1212    function tearDown() {
     13        _unregister_taxonomy( 'test_tax_cat' );
    1314        parent::tearDown();
    14 
    15         _unregister_taxonomy( 'test_tax_cat' );
    1615    }
    1716
  • trunk/tests/phpunit/tests/comment/getCommentsPagesCount.php

    r27055 r31622  
    2727     */
    2828    function tearDown() {
    29         parent::tearDown();
    3029        update_option( 'page_comments', $this->option_page_comments );
    3130        update_option( 'comments_per_page', $this->option_page_comments );
    3231        update_option( 'thread_comments', $this->option_page_comments );
    3332        update_option( 'posts_per_rss', $this->option_posts_per_rss );
     33        parent::tearDown();
    3434    }
    3535
  • trunk/tests/phpunit/tests/cron.php

    r29939 r31622  
    1414
    1515    function tearDown() {
    16         parent::tearDown();
    1716        // make sure the schedule is clear
    1817        _set_cron_array(array());
     18        parent::tearDown();
    1919    }
    2020
  • trunk/tests/phpunit/tests/customize/manager.php

    r31370 r31622  
    1717
    1818    function tearDown() {
    19         parent::tearDown();
    2019        $this->manager = null;
    2120        unset( $GLOBALS['wp_customize'] );
     21        parent::tearDown();
    2222    }
    2323
  • trunk/tests/phpunit/tests/customize/setting.php

    r31342 r31622  
    2727
    2828    function tearDown() {
    29         parent::tearDown();
    3029        $this->manager = null;
    3130        unset( $GLOBALS['wp_customize'] );
     31        parent::tearDown();
    3232    }
    3333
  • trunk/tests/phpunit/tests/customize/widgets.php

    r31426 r31622  
    3636
    3737    function tearDown() {
    38         parent::tearDown();
    3938        $this->manager = null;
    4039        unset( $GLOBALS['wp_customize'] );
    4140        unset( $GLOBALS['wp_scripts'] );
     41        parent::tearDown();
    4242    }
    4343
  • trunk/tests/phpunit/tests/image/base.php

    r30549 r31622  
    2323     */
    2424    public function tearDown() {
     25        remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
    2526        parent::tearDown();
    26 
    27         remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
    2827    }
    2928
  • trunk/tests/phpunit/tests/link.php

    r31114 r31622  
    77    function tearDown() {
    88        global $wp_rewrite;
     9        $wp_rewrite->init();
    910        parent::tearDown();
    10         $wp_rewrite->init();
    1111    }
    1212
  • trunk/tests/phpunit/tests/mail.php

    r30516 r31622  
    1212
    1313    function tearDown() {
     14        unset( $_SERVER['SERVER_NAME'] );
    1415        parent::tearDown();
    15         unset( $_SERVER['SERVER_NAME'] );
    1616    }
    1717
  • trunk/tests/phpunit/tests/multisite/bootstrap.php

    r29916 r31622  
    2222    function tearDown() {
    2323        global $wpdb;
     24        $wpdb->suppress_errors( $this->suppress );
    2425        parent::tearDown();
    25         $wpdb->suppress_errors( $this->suppress );
    2626    }
    2727
  • trunk/tests/phpunit/tests/multisite/ms-files-rewriting.php

    r30404 r31622  
    3030
    3131        update_site_option( 'ms_files_rewriting', 0 );
     32        $wpdb->suppress_errors( $this->suppress );
     33
    3234        parent::tearDown();
    33         $wpdb->suppress_errors( $this->suppress );
    3435    }
    3536
  • trunk/tests/phpunit/tests/multisite/network.php

    r30559 r31622  
    2323    function tearDown() {
    2424        global $wpdb;
     25        $wpdb->suppress_errors( $this->suppress );
    2526        parent::tearDown();
    26         $wpdb->suppress_errors( $this->suppress );
    2727    }
    2828
  • trunk/tests/phpunit/tests/multisite/site.php

    r31158 r31622  
    2222    function tearDown() {
    2323        global $wpdb;
     24        $wpdb->suppress_errors( $this->suppress );
    2425        parent::tearDown();
    25         $wpdb->suppress_errors( $this->suppress );
    2626    }
    2727
  • trunk/tests/phpunit/tests/option/multisite.php

    r29916 r31622  
    2323    function tearDown() {
    2424        global $wpdb;
     25        $wpdb->suppress_errors( $this->suppress );
    2526        parent::tearDown();
    26         $wpdb->suppress_errors( $this->suppress );
    2727    }
    2828
  • trunk/tests/phpunit/tests/post/meta.php

    r25002 r31622  
    3434
    3535    function tearDown() {
    36         parent::tearDown();
    3736        wp_delete_post($this->post_id);
    3837        wp_delete_post($this->post_id_2);
     38        parent::tearDown();
    3939    }
    4040
  • trunk/tests/phpunit/tests/post/revisions.php

    r30511 r31622  
    1313
    1414    function tearDown() {
     15        unset( $GLOBALS['wp_post_types'][ $this->post_type ] );
    1516        parent::tearDown();
    16         unset( $GLOBALS['wp_post_types'][ $this->post_type ] );
    1717    }
    1818
  • trunk/tests/phpunit/tests/query/conditionals.php

    r31458 r31622  
    3535    function tearDown() {
    3636        global $wp_rewrite;
     37        $wp_rewrite->init();
     38
    3739        parent::tearDown();
    38         $wp_rewrite->init();
    3940    }
    4041
  • trunk/tests/phpunit/tests/query/isTerm.php

    r31286 r31622  
    6060    function tearDown() {
    6161        global $wp_rewrite;
     62
     63        _unregister_taxonomy( 'testtax' );
     64
     65        $wp_rewrite->init();
     66
     67        remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
    6268        parent::tearDown();
    63 
    64         _unregister_taxonomy( 'testtax' );
    65 
    66         $wp_rewrite->init();
    67 
    68         remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
    6969    }
    7070
  • trunk/tests/phpunit/tests/query/search.php

    r27474 r31622  
    1919
    2020    function tearDown() {
    21         parent::tearDown();
    22 
    2321        _unregister_post_type( $this->post_type );
    2422        unset( $this->q );
     23
     24        parent::tearDown();
    2525    }
    2626
  • trunk/tests/phpunit/tests/rewrite.php

    r28966 r31622  
    2323    function tearDown() {
    2424        global $wp_rewrite;
     25        $wp_rewrite->init();
     26
    2527        parent::tearDown();
    26         $wp_rewrite->init();
    2728    }
    2829
  • trunk/tests/phpunit/tests/shortcode.php

    r30290 r31622  
    2121    function tearDown() {
    2222        global $shortcode_tags;
    23         parent::tearDown();
    2423        foreach ( $this->shortcodes as $shortcode )
    2524            unset( $shortcode_tags[ $shortcode ] );
     25        parent::tearDown();
    2626    }
    2727
  • trunk/tests/phpunit/tests/user/countUserPosts.php

    r30512 r31622  
    5858
    5959    public function tearDown() {
     60        _unregister_post_type( 'wptests_pt' );
    6061        parent::tearDown();
    61         _unregister_post_type( 'wptests_pt' );
    6262    }
    6363
  • trunk/tests/phpunit/tests/user/mapMetaCap.php

    r27390 r31622  
    3333
    3434    function tearDown() {
    35         parent::tearDown();
    36 
    3735        $GLOBALS['super_admins'] = $this->super_admins;
    3836        unset( $GLOBALS['wp_post_types'][ $this->post_type ] );
     37        parent::tearDown();
    3938    }
    4039
  • trunk/tests/phpunit/tests/user/multisite.php

    r29937 r31622  
    2323    function tearDown() {
    2424        global $wpdb;
     25        $wpdb->suppress_errors( $this->suppress );
    2526        parent::tearDown();
    26         $wpdb->suppress_errors( $this->suppress );
    2727    }
    2828
  • trunk/tests/phpunit/tests/xmlrpc/wp/getPage.php

    r25002 r31622  
    2525
    2626    function tearDown() {
     27        wp_delete_post( $this->post_id );
    2728        parent::tearDown();
    28 
    29         wp_delete_post( $this->post_id );
    3029    }
    3130
Note: See TracChangeset for help on using the changeset viewer.