1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +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:
epriestley 2012-10-22 16:25:00 -07:00
parent c0b9b6db54
commit cef6605b75

View file

@ -51,6 +51,7 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
private static $storageFixtureReferences = 0;
private static $storageFixture;
private static $storageFixtureObjectSeed = 0;
protected function getPhabricatorTestCaseConfiguration() {
return array();
@ -144,4 +145,34 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
'&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;
}
}