mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-02 03:32:42 +01:00
Add a generateNewTestUser() method to PhabricatorTestCase
Summary: I need this shortly and it seems like something we're likely to need more of in the future now that fixtures work. Test Plan: Ran unit tests. Used this productively in an upcoming diff. Reviewers: btrahan, vrana Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D3775
This commit is contained in:
parent
c0b9b6db54
commit
cef6605b75
1 changed files with 31 additions and 0 deletions
|
@ -51,6 +51,7 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
|
||||||
|
|
||||||
private static $storageFixtureReferences = 0;
|
private static $storageFixtureReferences = 0;
|
||||||
private static $storageFixture;
|
private static $storageFixture;
|
||||||
|
private static $storageFixtureObjectSeed = 0;
|
||||||
|
|
||||||
protected function getPhabricatorTestCaseConfiguration() {
|
protected function getPhabricatorTestCaseConfiguration() {
|
||||||
return array();
|
return array();
|
||||||
|
@ -144,4 +145,34 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
|
||||||
'&jump=true&context='.get_class($this);
|
'&jump=true&context='.get_class($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an integer seed to use when building unique identifiers (e.g.,
|
||||||
|
* non-colliding usernames). The seed is unstable and its value will change
|
||||||
|
* between test runs, so your tests must not rely on it.
|
||||||
|
*
|
||||||
|
* @return int A unique integer.
|
||||||
|
*/
|
||||||
|
protected function getNextObjectSeed() {
|
||||||
|
self::$storageFixtureObjectSeed += mt_rand(1, 100);
|
||||||
|
return self::$storageFixtureObjectSeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function generateNewTestUser() {
|
||||||
|
$seed = $this->getNextObjectSeed();
|
||||||
|
|
||||||
|
$user = id(new PhabricatorUser())
|
||||||
|
->setRealName("Test User {$seed}}")
|
||||||
|
->setUserName("test{$seed}");
|
||||||
|
|
||||||
|
$email = id(new PhabricatorUserEmail())
|
||||||
|
->setAddress("testuser{$seed}@example.com")
|
||||||
|
->setIsVerified(1);
|
||||||
|
|
||||||
|
$editor = new PhabricatorUserEditor();
|
||||||
|
$editor->setActor($user);
|
||||||
|
$editor->createNewUser($user, $email);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue