-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserFixtures.php
47 lines (43 loc) · 1.24 KB
/
UserFixtures.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace App\Utils\Database\DataFixtures;
use App\Domain\Entity\User;
use Doctrine\Common\Persistence\ObjectManager;
/**
* Class UserFixtures.
*
* Generate user fake starting set of data in database.
*/
class UserFixtures extends BaseFixture
{
/**
* Persist and flush entities in database.
*
* @param ObjectManager $manager
*
* @return void
*
* @throws \Exception
*/
public function loadData(ObjectManager $manager): void
{
$array = $this->parseYamlFile('user_fixtures.yaml');
$data = $array['users'];
// Create users
$this->createFixtures(User::class, \count($data), function ($i) use ($data) {
$user = new User(
$data[$i]['fields']['family_name'],
$data[$i]['fields']['first_name'],
$data[$i]['fields']['user_name'],
$data[$i]['fields']['email'],
$data[$i]['fields']['password'],
User::DEFAULT_ALGORITHM,
$data[$i]['fields']['roles'],
new \DateTime(sprintf("+%d days", -$i))
);
$user->modifyIsActivated(true);
return $user;
});
$manager->flush();
}
}