Skip to content

Commit 93a2713

Browse files
committed
Update createTestUser to avoid creating a master user by accident
1 parent beb4181 commit 93a2713

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

app/sprinkles/account/tests/withTestUser.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function createTestUser($isMaster = false, $login = false, array $para
5555
if ($isMaster) {
5656
$user_id = $this->ci->config['reserved_user_ids.master'];
5757
} else {
58-
$user_id = rand(0, 999999);
58+
$user_id = $this->getRandomUserId($this->ci->config['reserved_user_ids.master']);
5959
}
6060

6161
$params = array_merge(['id' => $user_id], $params);
@@ -70,6 +70,20 @@ protected function createTestUser($isMaster = false, $login = false, array $para
7070
return $user;
7171
}
7272

73+
/**
74+
* Returns a random user id, exclusing th master id
75+
* @param int $masterId
76+
* @return int
77+
*/
78+
protected function getRandomUserId($masterId)
79+
{
80+
do {
81+
$id = mt_rand(1, 9999);
82+
} while (in_array($id, [$masterId]));
83+
84+
return $id;
85+
}
86+
7387
/**
7488
* Gives a user a new test permission
7589
* @param UserInterface $user

0 commit comments

Comments
 (0)