From f7dbf962d7827ffc82fac7686221a2a1989a6246 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 10 Oct 2014 20:25:39 +0000 Subject: [PATCH] Only reset taxonomies and post types between tests when running core tests. A growing number of plugins and other WP-based projects use the core test tools, such as WP_UnitTestCase, as the basis of their own tests and continuous integration setups. At the same time, many of these third-party plugins use custom post types and taxonomies, which are generally registered a single time during a run of the tests: at 'init', before the testcases have run. Wiping out these globals between tests will mess with these third-party builds. Best practice for plugin developers is probably to clean up their own post types and taxonomies and then reinitialize before each test. But, in the interest of not breaking everyone's builds, the core test suite will not enforce this. Fixes #29827. git-svn-id: https://develop.svn.wordpress.org/trunk@29869 602fd350-edb4-49c9-b593-d223f7449a82 --- phpunit.xml.dist | 3 +++ tests/phpunit/includes/testcase.php | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2178ce2e42..abf5f00059 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -25,4 +25,7 @@ + + + diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 42301644fb..3e4065644e 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -37,8 +37,18 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { ini_set('display_errors', 1 ); $this->factory = new WP_UnitTest_Factory; $this->clean_up_global_scope(); - $this->reset_post_types(); - $this->reset_taxonomies(); + + /* + * When running core tests, ensure that post types and taxonomies + * are reset for each test. We skip this step for non-core tests, + * given the large number of plugins that register post types and + * taxonomies at 'init'. + */ + if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { + $this->reset_post_types(); + $this->reset_taxonomies(); + } + $this->start_transaction(); $this->expectDeprecated(); add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );