[TOOLS][TESTS] Add data fixtures, which populate the database with users used for testing

This commit is contained in:
Hugo Sales 2021-05-05 12:21:05 +00:00
parent ec1081ed43
commit 31b6211bd0
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace App\DataFixtures;
use App\Entity\GSActor;
use App\Entity\LocalGroup;
use App\Entity\LocalUser;
use App\Util\Nickname;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class NicknameFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
foreach ([LocalUser::class => ['taken_user', 'setId'], LocalGroup::class => ['taken_group', 'setGroupId']] as $entity => [$nick, $method]) {
$actor = GSActor::create(['nickname' => $nick, 'normalized_nickname' => Nickname::normalize($nick, check_already_used: false)]);
$manager->persist($actor);
$ent = $entity::create(['nickname' => $nick]);
$ent->{$method}($actor->getId());
$manager->persist($ent);
}
$manager->flush();
}
}