mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +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:
@@ -9,11 +9,7 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
protected static $editor_id;
|
||||
protected static $grammarian_id;
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$factory = new WP_UnitTest_Factory();
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
|
||||
|
||||
add_role( 'grammarian', 'Grammarian', array(
|
||||
@@ -24,13 +20,9 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
) );
|
||||
|
||||
self::$grammarian_id = $factory->user->create( array( 'role' => 'grammarian' ) );
|
||||
|
||||
self::commit_transaction();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass() {
|
||||
parent::tearDownAfterClass();
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
$ids = array( self::$editor_id, self::$grammarian_id );
|
||||
foreach ( $ids as $id ) {
|
||||
if ( is_multisite() ) {
|
||||
@@ -39,8 +31,6 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
wp_delete_user( $id );
|
||||
}
|
||||
}
|
||||
|
||||
self::commit_transaction();
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
|
||||
Reference in New Issue
Block a user