#35 done. LoadSubscribersData are now non-random.
This commit is contained in:
parent
144a535c6b
commit
1b2df8d4c3
|
@ -18,22 +18,22 @@ class LoadSubscribersData extends AbstractFixture implements OrderedFixtureInter
|
||||||
{
|
{
|
||||||
/** @var User[] $users */
|
/** @var User[] $users */
|
||||||
$users = [
|
$users = [
|
||||||
$this->getReference('test_user_99999'),
|
99999 => $this->getReference('test_user_99999'),
|
||||||
$this->getReference('test_user_99998'),
|
99998 => $this->getReference('test_user_99998'),
|
||||||
$this->getReference('test_user_99997'),
|
99997 => $this->getReference('test_user_99997'),
|
||||||
$this->getReference('test_user_99996'),
|
99996 => $this->getReference('test_user_99996'),
|
||||||
$this->getReference('test_user_99995'),
|
99995 => $this->getReference('test_user_99995'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$subscriptions = [
|
||||||
|
99999 => [99998, 99997, 99996, 99995],
|
||||||
|
99998 => [99999, 99997],
|
||||||
|
99997 => [99999],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($users as $key => $user) {
|
foreach ($users as $key => $user) {
|
||||||
// At least 2 subscribers for first user in the list
|
foreach ($subscriptions[$key] as $userId) {
|
||||||
if (0 === $key) {
|
$subscriber = $users[$userId];
|
||||||
$minimum = 2;
|
|
||||||
} else {
|
|
||||||
$minimum = random_int(0, count($users));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->getRandomSubscribers($users, $minimum) as $subscriber) {
|
|
||||||
$subscription = new Subscription($user, $subscriber);
|
$subscription = new Subscription($user, $subscriber);
|
||||||
$subscriptionEvent = new SubscriptionEvent($user, $subscriber, SubscriptionEvent::ACTION_SUBSCRIBE);
|
$subscriptionEvent = new SubscriptionEvent($user, $subscriber, SubscriptionEvent::ACTION_SUBSCRIBE);
|
||||||
$om->persist($subscription);
|
$om->persist($subscription);
|
||||||
|
@ -49,34 +49,4 @@ class LoadSubscribersData extends AbstractFixture implements OrderedFixtureInter
|
||||||
{
|
{
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns array with random users from given users array
|
|
||||||
*
|
|
||||||
* @param User[] $users
|
|
||||||
* @param int $min
|
|
||||||
*
|
|
||||||
* @return User[]
|
|
||||||
*/
|
|
||||||
private function getRandomSubscribers(array $users, int $min = 0): array
|
|
||||||
{
|
|
||||||
if (0 === $number = mt_rand($min, count($users))) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$keys = array_rand($users, $number);
|
|
||||||
|
|
||||||
// If array_rand was called with $number = 1
|
|
||||||
if (!is_array($keys)) {
|
|
||||||
$keys = [$keys];
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
|
||||||
$result[] = $users[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue