Unit Tests:

* Automatically delete objects that we were created during `wpSetUpBeforeClass` - posts, comments, terms (except 1), and user (except 1)
* The amount of leftover data between tests was breathtaking - use the new function: `_delete_all_data()`
* Commit database transactions for all `TestCase`s, not just those that implement `wpSetUpBeforeClass` and `wpTearDownAfterClass`
* The tests run 10-20 seconds faster now

See #37699.


git-svn-id: https://develop.svn.wordpress.org/trunk@38398 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2016-08-27 08:35:16 +00:00
parent f0af25bd80
commit 02319efa71
51 changed files with 60 additions and 371 deletions
+8 -3
View File
@@ -61,6 +61,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
$c = self::get_called_class();
if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) {
self::commit_transaction();
return;
}
@@ -72,8 +73,12 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
public static function tearDownAfterClass() {
parent::tearDownAfterClass();
_delete_all_data();
self::flush_cache();
$c = self::get_called_class();
if ( ! method_exists( $c, 'wpTearDownAfterClass' ) ) {
self::commit_transaction();
return;
}
@@ -158,7 +163,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
function clean_up_global_scope() {
$_GET = array();
$_POST = array();
$this->flush_cache();
self::flush_cache();
}
/**
@@ -243,7 +248,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
}
}
function flush_cache() {
static function flush_cache() {
global $wp_object_cache;
$wp_object_cache->group_ops = array();
$wp_object_cache->stats = array();
@@ -445,7 +450,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
$_SERVER['REQUEST_URI'] = $req;
unset($_SERVER['PATH_INFO']);
$this->flush_cache();
self::flush_cache();
unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']);
$GLOBALS['wp_the_query'] = new WP_Query();
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];