mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 20:54:29 +00:00
Unit Tests: implement setUpBeforeClass() and tearDownAfterClass() on WP_UnitTestCase. Use late static binding (plus a gross fallback for PHP 5.2) to check if wpSetUpBeforeClass() or wpTearDownAfterClass() exist on the called class, and then call it and pass a static WP_UnitTest_Factory instance via Dependency Injection, if it exists.
This makes it way easier to add fixtures, and tear them down, without needing to instantiate `WP_UnitTest_Factory` in every class - removes the need to call `commit_transaction()` in each individual class. See #30017, #33968. git-svn-id: https://develop.svn.wordpress.org/trunk@35186 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -8,9 +8,7 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
|
||||
static $user_id;
|
||||
static $post_ids = array();
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
$factory = new WP_UnitTest_Factory();
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$user_id = $factory->user->create( array(
|
||||
'role' => 'author',
|
||||
'user_login' => 'count_user_posts_user',
|
||||
@@ -33,11 +31,9 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
|
||||
'post_author' => 12345,
|
||||
'post_type' => 'wptests_pt',
|
||||
) ) );
|
||||
|
||||
self::commit_transaction();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass() {
|
||||
public static function wpTearDownAfterClass() {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( self::$user_id );
|
||||
} else {
|
||||
@@ -47,8 +43,6 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
|
||||
foreach ( self::$post_ids as $post_id ) {
|
||||
wp_delete_post( $post_id, true );
|
||||
}
|
||||
|
||||
self::commit_transaction();
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
|
||||
Reference in New Issue
Block a user