summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJohn Blackbourn <johnbillion@git.wordpress.org>2021-02-27 17:08:26 +0000
committerJohn Blackbourn <johnbillion@git.wordpress.org>2021-02-27 17:08:26 +0000
commit055deeabff74e1a327fd7142f719622f7b6ff81e (patch)
tree864bf0fec2f21236e9d02e6582f0eef9c388c15c
parent3542c3b4c0f40c6df81a6f475491b017f5f92263 (diff)
downloadwordpress-055deeabff74e1a327fd7142f719622f7b6ff81e.tar.gz
wordpress-055deeabff74e1a327fd7142f719622f7b6ff81e.zip
Build/Test Tools: Fix and standardise calls to the `tearDown()` method in the test suite.
The parent method should be called after any test-specific teardown. See #52625 git-svn-id: https://develop.svn.wordpress.org/trunk@50450 602fd350-edb4-49c9-b593-d223f7449a82
-rw-r--r--tests/phpunit/includes/testcase-ajax.php2
-rw-r--r--tests/phpunit/includes/testcase-block-supports.php4
-rw-r--r--tests/phpunit/includes/testcase-rest-controller.php2
-rw-r--r--tests/phpunit/tests/ajax/CustomizeManager.php2
-rw-r--r--tests/phpunit/tests/auth.php4
-rw-r--r--tests/phpunit/tests/blocks/block-context.php4
-rw-r--r--tests/phpunit/tests/blocks/block-list.php4
-rw-r--r--tests/phpunit/tests/blocks/block-type-registry.php4
-rw-r--r--tests/phpunit/tests/blocks/block.php4
-rw-r--r--tests/phpunit/tests/blocks/register.php4
-rw-r--r--tests/phpunit/tests/blocks/render.php4
-rw-r--r--tests/phpunit/tests/customize/custom-css-setting.php2
-rw-r--r--tests/phpunit/tests/dbdelta.php1
-rw-r--r--tests/phpunit/tests/formatting/ExcerptRemoveBlocks.php3
-rw-r--r--tests/phpunit/tests/functions/deprecated.php2
-rw-r--r--tests/phpunit/tests/functions/referer.php4
-rw-r--r--tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php2
-rw-r--r--tests/phpunit/tests/multisite.php2
-rw-r--r--tests/phpunit/tests/oembed/controller.php2
-rw-r--r--tests/phpunit/tests/query/commentCount.php2
-rw-r--r--tests/phpunit/tests/rest-api/rest-application-passwords-controller.php2
-rw-r--r--tests/phpunit/tests/rest-api/rest-attachments-controller.php4
-rw-r--r--tests/phpunit/tests/rest-api/rest-controller.php4
-rw-r--r--tests/phpunit/tests/rest-api/rest-plugins-controller.php4
-rw-r--r--tests/phpunit/tests/rest-api/rest-schema-setup.php3
-rw-r--r--tests/phpunit/tests/rest-api/rest-settings-controller.php4
-rw-r--r--tests/phpunit/tests/rest-api/rest-taxonomies-controller.php4
-rw-r--r--tests/phpunit/tests/rewrite/oldDateRedirect.php4
-rw-r--r--tests/phpunit/tests/rewrite/oldSlugRedirect.php3
29 files changed, 43 insertions, 47 deletions
diff --git a/tests/phpunit/includes/testcase-ajax.php b/tests/phpunit/includes/testcase-ajax.php
index 34fd32a392..c6db8305c6 100644
--- a/tests/phpunit/includes/testcase-ajax.php
+++ b/tests/phpunit/includes/testcase-ajax.php
@@ -157,7 +157,6 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
* Resets $_POST, removes the wp_die() override, restores error reporting.
*/
public function tearDown() {
- parent::tearDown();
$_POST = array();
$_GET = array();
unset( $GLOBALS['post'] );
@@ -166,6 +165,7 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
remove_action( 'clear_auth_cookie', array( $this, 'logout' ) );
error_reporting( $this->_error_level );
set_current_screen( 'front' );
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/includes/testcase-block-supports.php b/tests/phpunit/includes/testcase-block-supports.php
index f54dba8b9f..981bfcd190 100644
--- a/tests/phpunit/includes/testcase-block-supports.php
+++ b/tests/phpunit/includes/testcase-block-supports.php
@@ -19,12 +19,12 @@ class Block_Supported_Styles_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
- parent::tearDown();
-
while ( ! empty( $this->registered_block_names ) ) {
$block_name = array_pop( $this->registered_block_names );
unregister_block_type( $block_name );
}
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/includes/testcase-rest-controller.php b/tests/phpunit/includes/testcase-rest-controller.php
index bc7d409368..2c79df11be 100644
--- a/tests/phpunit/includes/testcase-rest-controller.php
+++ b/tests/phpunit/includes/testcase-rest-controller.php
@@ -14,11 +14,11 @@ abstract class WP_Test_REST_Controller_Testcase extends WP_Test_REST_TestCase {
}
public function tearDown() {
- parent::tearDown();
remove_filter( 'rest_url', array( $this, 'test_rest_url_for_leading_slash' ), 10, 2 );
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
+ parent::tearDown();
}
abstract public function test_register_routes();
diff --git a/tests/phpunit/tests/ajax/CustomizeManager.php b/tests/phpunit/tests/ajax/CustomizeManager.php
index ab63bb65f0..b5ad859702 100644
--- a/tests/phpunit/tests/ajax/CustomizeManager.php
+++ b/tests/phpunit/tests/ajax/CustomizeManager.php
@@ -59,8 +59,8 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
* Tear down.
*/
public function tearDown() {
- parent::tearDown();
$_REQUEST = array();
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/auth.php b/tests/phpunit/tests/auth.php
index de0a498b84..4e665ae8f3 100644
--- a/tests/phpunit/tests/auth.php
+++ b/tests/phpunit/tests/auth.php
@@ -43,10 +43,10 @@ class Tests_Auth extends WP_UnitTestCase {
}
public function tearDown() {
- parent::tearDown();
-
// Cleanup all the global state.
unset( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $GLOBALS['wp_rest_application_password_status'], $GLOBALS['wp_rest_application_password_uuid'] );
+
+ parent::tearDown();
}
function test_auth_cookie_valid() {
diff --git a/tests/phpunit/tests/blocks/block-context.php b/tests/phpunit/tests/blocks/block-context.php
index b3eff8565a..7089ebb84b 100644
--- a/tests/phpunit/tests/blocks/block-context.php
+++ b/tests/phpunit/tests/blocks/block-context.php
@@ -44,12 +44,12 @@ class WP_Block_Context_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
- parent::tearDown();
-
while ( ! empty( $this->registered_block_names ) ) {
$block_name = array_pop( $this->registered_block_names );
unregister_block_type( $block_name );
}
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/blocks/block-list.php b/tests/phpunit/tests/blocks/block-list.php
index 7757faafc5..b9ab45dbcf 100644
--- a/tests/phpunit/tests/blocks/block-list.php
+++ b/tests/phpunit/tests/blocks/block-list.php
@@ -37,9 +37,9 @@ class WP_Block_List_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
- parent::tearDown();
-
$this->registry = null;
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/blocks/block-type-registry.php b/tests/phpunit/tests/blocks/block-type-registry.php
index 78c2a5e699..d46b46685a 100644
--- a/tests/phpunit/tests/blocks/block-type-registry.php
+++ b/tests/phpunit/tests/blocks/block-type-registry.php
@@ -41,9 +41,9 @@ class WP_Test_Block_Type_Registry extends WP_UnitTestCase {
* @since 5.0.0
*/
public function tearDown() {
- parent::tearDown();
-
$this->registry = null;
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/blocks/block.php b/tests/phpunit/tests/blocks/block.php
index 84e2ff903a..7a036cb638 100644
--- a/tests/phpunit/tests/blocks/block.php
+++ b/tests/phpunit/tests/blocks/block.php
@@ -36,9 +36,9 @@ class WP_Block_Test extends WP_UnitTestCase {
* Tear down each test method.
*/
public function tearDown() {
- parent::tearDown();
-
$this->registry = null;
+
+ parent::tearDown();
}
function filter_render_block( $content, $parsed_block ) {
diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php
index 1d6e845d6f..bedcf799e4 100644
--- a/tests/phpunit/tests/blocks/register.php
+++ b/tests/phpunit/tests/blocks/register.php
@@ -58,8 +58,6 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
* @since 5.0.0
*/
function tearDown() {
- parent::tearDown();
-
$registry = WP_Block_Type_Registry::get_instance();
foreach ( array( 'core/test-static', 'core/test-dynamic', 'tests/notice' ) as $block_name ) {
@@ -67,6 +65,8 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
$registry->unregister( $block_name );
}
}
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/blocks/render.php b/tests/phpunit/tests/blocks/render.php
index 04a3b27027..aa9cf7cf65 100644
--- a/tests/phpunit/tests/blocks/render.php
+++ b/tests/phpunit/tests/blocks/render.php
@@ -38,8 +38,6 @@ class WP_Test_Block_Render extends WP_UnitTestCase {
* @since 5.0.0
*/
public function tearDown() {
- parent::tearDown();
-
$this->test_block_instance_number = 0;
$registry = WP_Block_Type_Registry::get_instance();
@@ -49,6 +47,8 @@ class WP_Test_Block_Render extends WP_UnitTestCase {
if ( $registry->is_registered( 'core/dynamic' ) ) {
$registry->unregister( 'core/dynamic' );
}
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/customize/custom-css-setting.php b/tests/phpunit/tests/customize/custom-css-setting.php
index 9c246c63ea..3618a288d6 100644
--- a/tests/phpunit/tests/customize/custom-css-setting.php
+++ b/tests/phpunit/tests/customize/custom-css-setting.php
@@ -55,8 +55,8 @@ class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase {
* Tear down the test case.
*/
function tearDown() {
- parent::tearDown();
$this->setting = null;
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/dbdelta.php b/tests/phpunit/tests/dbdelta.php
index ae8d69c5ad..adee83e450 100644
--- a/tests/phpunit/tests/dbdelta.php
+++ b/tests/phpunit/tests/dbdelta.php
@@ -93,6 +93,7 @@ class Tests_dbDelta extends WP_UnitTestCase {
parent::tearDown();
+ // This has to be called after the parent `tearDown()` method.
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test" );
}
diff --git a/tests/phpunit/tests/formatting/ExcerptRemoveBlocks.php b/tests/phpunit/tests/formatting/ExcerptRemoveBlocks.php
index 70efe18d55..01b2918bed 100644
--- a/tests/phpunit/tests/formatting/ExcerptRemoveBlocks.php
+++ b/tests/phpunit/tests/formatting/ExcerptRemoveBlocks.php
@@ -81,10 +81,11 @@ class Tests_Formatting_ExcerptRemoveBlocks extends WP_UnitTestCase {
* @since 5.2.0
*/
function tearDown() {
- parent::tearDown();
$registry = WP_Block_Type_Registry::get_instance();
$registry->unregister( 'core/fake' );
wp_delete_post( self::$post_id, true );
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/functions/deprecated.php b/tests/phpunit/tests/functions/deprecated.php
index b9b86455c1..6d8f5f6de0 100644
--- a/tests/phpunit/tests/functions/deprecated.php
+++ b/tests/phpunit/tests/functions/deprecated.php
@@ -53,7 +53,7 @@ class Tests_Functions_Deprecated extends WP_UnitTestCase {
/**
* Tears down the test fixture.
*/
- public function teardown() {
+ public function tearDown() {
remove_action( 'deprecated_function_run', array( $this, 'deprecated_function' ), 10, 3 );
remove_action( 'deprecated_function_trigger_error', '__return_false' );
remove_action( 'deprecated_argument_run', array( $this, 'deprecated_argument' ), 10, 3 );
diff --git a/tests/phpunit/tests/functions/referer.php b/tests/phpunit/tests/functions/referer.php
index a6a1aaed99..220d016139 100644
--- a/tests/phpunit/tests/functions/referer.php
+++ b/tests/phpunit/tests/functions/referer.php
@@ -18,11 +18,11 @@ class Tests_Functions_Referer extends WP_UnitTestCase {
}
public function tearDown() {
- parent::tearDown();
-
$_SERVER['HTTP_REFERER'] = '';
$_SERVER['REQUEST_URI'] = '';
$_REQUEST['_wp_http_referer'] = '';
+
+ parent::tearDown();
}
public function _fake_subfolder_install() {
diff --git a/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php b/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
index dda5845cc1..ed9c2cf25a 100644
--- a/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
+++ b/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
@@ -27,8 +27,8 @@ class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase {
*/
function tearDown() {
global $current_screen;
- parent::tearDown();
$current_screen = $this->current_screen;
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/multisite.php b/tests/phpunit/tests/multisite.php
index e96f3d27ce..085d155819 100644
--- a/tests/phpunit/tests/multisite.php
+++ b/tests/phpunit/tests/multisite.php
@@ -18,8 +18,8 @@ if ( is_multisite() ) :
function tearDown() {
global $wpdb;
- parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
+ parent::tearDown();
}
function test_wpmu_log_new_registrations() {
diff --git a/tests/phpunit/tests/oembed/controller.php b/tests/phpunit/tests/oembed/controller.php
index f39c74f5d0..d6be39409b 100644
--- a/tests/phpunit/tests/oembed/controller.php
+++ b/tests/phpunit/tests/oembed/controller.php
@@ -60,13 +60,13 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
}
public function tearDown() {
- parent::tearDown();
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 );
remove_filter( 'oembed_result', array( $this, 'filter_oembed_result' ), 10 );
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/query/commentCount.php b/tests/phpunit/tests/query/commentCount.php
index fb1bb56e45..6c1b85eb5b 100644
--- a/tests/phpunit/tests/query/commentCount.php
+++ b/tests/phpunit/tests/query/commentCount.php
@@ -14,8 +14,8 @@ class Tests_Query_CommentCount extends WP_UnitTestCase {
}
public function tearDown() {
- parent::tearDown();
unset( $this->q );
+ parent::tearDown();
}
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
diff --git a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
index 4b819426d6..91ed93939a 100644
--- a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
@@ -70,8 +70,8 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
}
public function tearDown() {
- parent::tearDown();
unset( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $GLOBALS['wp_rest_application_password_status'], $GLOBALS['wp_rest_application_password_uuid'] );
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
index c023033369..fe3c669c17 100644
--- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
@@ -88,8 +88,6 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
public function tearDown() {
- parent::tearDown();
-
if ( file_exists( $this->test_file ) ) {
unlink( $this->test_file );
}
@@ -107,6 +105,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
WP_Image_Editor_Mock::$edit_return = array();
WP_Image_Editor_Mock::$size_return = null;
}
+
+ parent::tearDown();
}
public function test_register_routes() {
diff --git a/tests/phpunit/tests/rest-api/rest-controller.php b/tests/phpunit/tests/rest-api/rest-controller.php
index d9841c7d86..717bc1b214 100644
--- a/tests/phpunit/tests/rest-api/rest-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-controller.php
@@ -53,10 +53,10 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase {
}
public function tearDown() {
- parent::tearDown();
-
global $wp_rest_additional_fields;
$wp_rest_additional_fields = array();
+
+ parent::tearDown();
}
public function test_validate_schema_type_integer() {
diff --git a/tests/phpunit/tests/rest-api/rest-plugins-controller.php b/tests/phpunit/tests/rest-api/rest-plugins-controller.php
index bab1e87ec9..2448e274a2 100644
--- a/tests/phpunit/tests/rest-api/rest-plugins-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-plugins-controller.php
@@ -83,11 +83,11 @@ class WP_REST_Plugins_Controller_Test extends WP_Test_REST_Controller_Testcase {
}
public function tearDown() {
- parent::tearDown();
-
if ( file_exists( WP_PLUGIN_DIR . '/test-plugin/test-plugin.php' ) ) {
$this->rmdir( WP_PLUGIN_DIR . '/test-plugin' );
}
+
+ parent::tearDown();
}
/**
diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php
index 69e265047b..5f9bf079e2 100644
--- a/tests/phpunit/tests/rest-api/rest-schema-setup.php
+++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php
@@ -27,13 +27,12 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
}
public function tearDown() {
- parent::tearDown();
-
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$wp_rest_server = null;
remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
+ parent::tearDown();
}
public function mock_embed_request( $preempt, $r, $url ) {
diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php
index c9aab41f74..d8814c6ff9 100644
--- a/tests/phpunit/tests/rest-api/rest-settings-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php
@@ -39,8 +39,6 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
}
public function tearDown() {
- parent::tearDown();
-
$settings_to_unregister = array(
'mycustomsetting',
'mycustomsetting1',
@@ -55,6 +53,8 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
unregister_setting( 'somegroup', $setting );
}
}
+
+ parent::tearDown();
}
public function test_register_routes() {
diff --git a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
index d8cf72768b..e624c14dc1 100644
--- a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
@@ -232,10 +232,6 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas
$this->assertArrayHasKey( 'rest_base', $properties );
}
- public function tearDown() {
- parent::tearDown();
- }
-
/**
* Utility function for use in get_public_taxonomies
*/
diff --git a/tests/phpunit/tests/rewrite/oldDateRedirect.php b/tests/phpunit/tests/rewrite/oldDateRedirect.php
index c0b50a2dbd..d413006b5a 100644
--- a/tests/phpunit/tests/rewrite/oldDateRedirect.php
+++ b/tests/phpunit/tests/rewrite/oldDateRedirect.php
@@ -42,9 +42,9 @@ class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase {
}
public function tearDown() {
- parent::tearDown();
-
$this->old_date_redirect_url = null;
+
+ parent::tearDown();
}
public function test_old_date_redirect() {
diff --git a/tests/phpunit/tests/rewrite/oldSlugRedirect.php b/tests/phpunit/tests/rewrite/oldSlugRedirect.php
index 2bd27398ad..7177cbfa1e 100644
--- a/tests/phpunit/tests/rewrite/oldSlugRedirect.php
+++ b/tests/phpunit/tests/rewrite/oldSlugRedirect.php
@@ -30,11 +30,10 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase {
}
public function tearDown() {
- parent::tearDown();
-
$this->old_slug_redirect_url = null;
remove_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10 );
+ parent::tearDown();
}
public function test_old_slug_redirect() {