mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-20 03:04:27 +00:00
Unit Tests: one $factory to rule them all, and it shall be static.
Using more than one instance of `WP_UnitTest_Factory` causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use `setUpBeforeClass`, we were creating ad hoc instances. To avoid that, we were injecting one `static` instance via Dependency Injection in `wpSetUpBeforeClass`. All tests should really use the `static` instance, so we will remove the instance prop `$factory`. Replace `$this->factory` with `self::$factory` over 2000 times. Rewrite all of the tests that were hard-coding dynamic values. #YOLOFriday git-svn-id: https://develop.svn.wordpress.org/trunk@35225 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -17,25 +17,25 @@ class Tests_User_CountUsers extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
// Setup users
|
||||
$admin = $this->factory->user->create( array(
|
||||
$admin = self::$factory->user->create( array(
|
||||
'role' => 'administrator',
|
||||
) );
|
||||
$editor = $this->factory->user->create( array(
|
||||
$editor = self::$factory->user->create( array(
|
||||
'role' => 'editor',
|
||||
) );
|
||||
$author = $this->factory->user->create( array(
|
||||
$author = self::$factory->user->create( array(
|
||||
'role' => 'author',
|
||||
) );
|
||||
$contributor = $this->factory->user->create( array(
|
||||
$contributor = self::$factory->user->create( array(
|
||||
'role' => 'contributor',
|
||||
) );
|
||||
$subscriber = $this->factory->user->create( array(
|
||||
$subscriber = self::$factory->user->create( array(
|
||||
'role' => 'subscriber',
|
||||
) );
|
||||
$none = $this->factory->user->create( array(
|
||||
$none = self::$factory->user->create( array(
|
||||
'role' => '',
|
||||
) );
|
||||
$nobody = $this->factory->user->create( array(
|
||||
$nobody = self::$factory->user->create( array(
|
||||
'role' => '',
|
||||
) );
|
||||
|
||||
@@ -67,33 +67,33 @@ class Tests_User_CountUsers extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
// Setup users
|
||||
$admin = $this->factory->user->create( array(
|
||||
$admin = self::$factory->user->create( array(
|
||||
'role' => 'administrator',
|
||||
) );
|
||||
$editor = $this->factory->user->create( array(
|
||||
$editor = self::$factory->user->create( array(
|
||||
'role' => 'editor',
|
||||
) );
|
||||
$author = $this->factory->user->create( array(
|
||||
$author = self::$factory->user->create( array(
|
||||
'role' => 'author',
|
||||
) );
|
||||
$contributor = $this->factory->user->create( array(
|
||||
$contributor = self::$factory->user->create( array(
|
||||
'role' => 'contributor',
|
||||
) );
|
||||
$subscriber = $this->factory->user->create( array(
|
||||
$subscriber = self::$factory->user->create( array(
|
||||
'role' => 'subscriber',
|
||||
) );
|
||||
$none = $this->factory->user->create( array(
|
||||
$none = self::$factory->user->create( array(
|
||||
'role' => '',
|
||||
) );
|
||||
$nobody = $this->factory->user->create( array(
|
||||
$nobody = self::$factory->user->create( array(
|
||||
'role' => '',
|
||||
) );
|
||||
|
||||
// Setup blogs
|
||||
$blog_1 = (int) $this->factory->blog->create( array(
|
||||
$blog_1 = (int) self::$factory->blog->create( array(
|
||||
'user_id' => $editor,
|
||||
) );
|
||||
$blog_2 = (int) $this->factory->blog->create( array(
|
||||
$blog_2 = (int) self::$factory->blog->create( array(
|
||||
'user_id' => $author,
|
||||
) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user