Skip to content

Commit

Permalink
Changed creation of random users in fixture loading in dev environmen…
Browse files Browse the repository at this point in the history
…t to speed up fixture loading
  • Loading branch information
Felix Ruf committed Jul 3, 2024
1 parent 488e2c3 commit 17402d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Mealz/MealBundle/DataFixtures/ORM/LoadParticipants.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function load(ObjectManager $manager): void
$this->objectManager = $manager;
$this->loadReferences();

// braucht ca. 8sek
$this->loadSimpleMealParticipants();
$this->loadCombinedMealParticipants();

Expand Down
17 changes: 12 additions & 5 deletions src/Mealz/UserBundle/DataFixtures/ORM/LoadUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function load(ObjectManager $manager): void
$this->addUser($user['username'], $user['password'], $user['firstName'], $user['lastName'], $user['roles']);
}

for ($i = 0; $i < 50; ++$i) {
for ($i = 0; $i < 20; ++$i) {
$this->createRandUser();
}

Expand All @@ -114,13 +114,19 @@ protected function addUser(
string $password,
string $firstName,
string $lastName,
array $roles
array $roles,
bool $isRandUser = false
): void {
$login = new Login();
$login->setUsername($username);

$hashedPassword = $this->passwordHasher->hashPassword($login, $password);
$login->setPassword($hashedPassword);
$environment = getenv('APP_ENV');
if (false === $isRandUser && $environment !== 'prod' && $environment !== 'staging') {
$hashedPassword = $this->passwordHasher->hashPassword($login, $password);
$login->setPassword($hashedPassword);
} else {
$login->setPassword($password);
}

$profile = new Profile();
$profile->setUsername($username);
Expand Down Expand Up @@ -170,7 +176,8 @@ protected function createRandUser(): void
$randPass,
$randFirstName,
$randLastName,
['ROLE_USER']
['ROLE_USER'],
true
);
}
}

0 comments on commit 17402d5

Please sign in to comment.