mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 06:37:06 +00:00
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:
@@ -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'];
|
||||
|
||||
Reference in New Issue
Block a user