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.

git-svn-id: https://develop.svn.wordpress.org/trunk@31622 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-03-05 13:14:15 +00:00
parent 889edda453
commit 067fa3702e
33 changed files with 37 additions and 38 deletions

View File

@ -37,9 +37,9 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
unset( $GLOBALS['wp_taxonomies']['old-or-new'] );
set_current_screen( 'front' );
parent::tearDown();
}
function test_set_current_screen_with_hook_suffix() {

View File

@ -46,8 +46,8 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
* Reset the current user
*/
public function tearDown() {
parent::tearDown();
wp_set_current_user( 0 );
parent::tearDown();
}
/**

View File

@ -43,8 +43,8 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
remove_filter( 'query', array( $this, '_block_comments' ) );
parent::tearDown();
}
/**

View File

@ -36,9 +36,9 @@ class Tests_Ajax_Response extends WP_UnitTestCase {
* Remove the wp_die() override, restore error reporting
*/
public function tearDown() {
parent::tearDown();
remove_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
error_reporting( $this->_error_level );
parent::tearDown();
}
/**

View File

@ -13,8 +13,8 @@ class Tests_Basic extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
$this->val = false;
parent::tearDown();
}
function test_true() {

View File

@ -14,8 +14,8 @@ class Tests_Cache extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
$this->flush_cache();
parent::tearDown();
}
function &init_cache() {

View File

@ -23,8 +23,8 @@ class Tests_Canonical extends WP_Canonical_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
wp_set_current_user( self::$old_current_user );
parent::tearDown();
}
/**

View File

@ -26,8 +26,8 @@ class Tests_Canonical_PageOnFront extends WP_Canonical_UnitTestCase {
function tearDown() {
global $wp_rewrite;
parent::tearDown();
$wp_rewrite->init();
parent::tearDown();
}
/**

View File

@ -10,9 +10,8 @@
class Tests_Category extends WP_UnitTestCase {
function tearDown() {
parent::tearDown();
_unregister_taxonomy( 'test_tax_cat' );
parent::tearDown();
}
/**

View File

@ -26,11 +26,11 @@ class Tests_Comment_GetCommentsPagesCount extends WP_UnitTestCase {
* tearDown options
*/
function tearDown() {
parent::tearDown();
update_option( 'page_comments', $this->option_page_comments );
update_option( 'comments_per_page', $this->option_page_comments );
update_option( 'thread_comments', $this->option_page_comments );
update_option( 'posts_per_rss', $this->option_posts_per_rss );
parent::tearDown();
}
/**

View File

@ -13,9 +13,9 @@ class Tests_Cron extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
// make sure the schedule is clear
_set_cron_array(array());
parent::tearDown();
}
function test_wp_get_schedule_empty() {

View File

@ -16,9 +16,9 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
$this->manager = null;
unset( $GLOBALS['wp_customize'] );
parent::tearDown();
}
/**

View File

@ -26,9 +26,9 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
$this->manager = null;
unset( $GLOBALS['wp_customize'] );
parent::tearDown();
}
function test_constructor_without_args() {

View File

@ -35,10 +35,10 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
$this->manager = null;
unset( $GLOBALS['wp_customize'] );
unset( $GLOBALS['wp_scripts'] );
parent::tearDown();
}
function set_customized_post_data( $customized ) {

View File

@ -22,9 +22,8 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
* Undo the image editor override
*/
public function tearDown() {
parent::tearDown();
remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
parent::tearDown();
}
/**

View File

@ -6,8 +6,8 @@ class Tests_Link extends WP_UnitTestCase {
function tearDown() {
global $wp_rewrite;
parent::tearDown();
$wp_rewrite->init();
parent::tearDown();
}
function _get_pagenum_link_cb( $url ) {

View File

@ -11,8 +11,8 @@ class Tests_Mail extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
unset( $_SERVER['SERVER_NAME'] );
parent::tearDown();
}
function test_wp_mail_custom_boundaries() {

View File

@ -21,8 +21,8 @@ class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}

View File

@ -29,8 +29,9 @@ class Tests_Multisite_MS_Files_Rewriting extends WP_UnitTestCase {
global $wpdb;
update_site_option( 'ms_files_rewriting', 0 );
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}
function test_switch_upload_dir() {

View File

@ -22,8 +22,8 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}
/**

View File

@ -21,8 +21,8 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}
function test_switch_restore_blog() {

View File

@ -22,8 +22,8 @@ class Tests_Multisite_Option extends WP_UnitTestCase {
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}
function test_from_same_site() {

View File

@ -33,9 +33,9 @@ class Tests_Post_Meta extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
wp_delete_post($this->post_id);
wp_delete_post($this->post_id_2);
parent::tearDown();
}
function test_unique_postmeta() {

View File

@ -12,8 +12,8 @@ class Tests_Post_Revisions extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
unset( $GLOBALS['wp_post_types'][ $this->post_type ] );
parent::tearDown();
}
/**

View File

@ -34,8 +34,9 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
function tearDown() {
global $wp_rewrite;
parent::tearDown();
$wp_rewrite->init();
parent::tearDown();
}
function test_home() {

View File

@ -59,13 +59,13 @@ class Tests_Query_IsTerm extends WP_UnitTestCase {
function tearDown() {
global $wp_rewrite;
parent::tearDown();
_unregister_taxonomy( 'testtax' );
$wp_rewrite->init();
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
parent::tearDown();
}
function test_tag_action_tax() {

View File

@ -18,10 +18,10 @@ class Tests_Query_Search extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
_unregister_post_type( $this->post_type );
unset( $this->q );
parent::tearDown();
}
function get_search_results( $terms ) {

View File

@ -22,8 +22,9 @@ class Tests_Rewrite extends WP_UnitTestCase {
function tearDown() {
global $wp_rewrite;
parent::tearDown();
$wp_rewrite->init();
parent::tearDown();
}
function test_url_to_postid() {

View File

@ -20,9 +20,9 @@ class Tests_Shortcode extends WP_UnitTestCase {
function tearDown() {
global $shortcode_tags;
parent::tearDown();
foreach ( $this->shortcodes as $shortcode )
unset( $shortcode_tags[ $shortcode ] );
parent::tearDown();
}
function _shortcode_test_shortcode_tag( $atts, $content = null, $tagname = null ) {

View File

@ -57,8 +57,8 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
}
public function tearDown() {
parent::tearDown();
_unregister_post_type( 'wptests_pt' );
parent::tearDown();
}
public function test_count_user_posts_post_type_should_default_to_post() {

View File

@ -32,10 +32,9 @@ class Tests_User_MapMetaCap extends WP_UnitTestCase {
}
function tearDown() {
parent::tearDown();
$GLOBALS['super_admins'] = $this->super_admins;
unset( $GLOBALS['wp_post_types'][ $this->post_type ] );
parent::tearDown();
}
function test_capability_type_post_with_no_extra_caps() {

View File

@ -22,8 +22,8 @@ class Tests_Multisite_User extends WP_UnitTestCase {
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
parent::tearDown();
}
function test_remove_user_from_blog() {

View File

@ -24,9 +24,8 @@ class Tests_XMLRPC_wp_getPage extends WP_XMLRPC_UnitTestCase {
}
function tearDown() {
parent::tearDown();
wp_delete_post( $this->post_id );
parent::tearDown();
}
function test_invalid_username_password() {