This commit is contained in:
2025-11-01 10:59:26 +01:00
parent f886f0f6c2
commit 9315b27898
13 changed files with 203 additions and 120 deletions

View File

@@ -6,11 +6,13 @@ namespace Tvdt\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Tvdt\Entity\Season;
use Tvdt\Entity\User;
final class TestFixtures extends Fixture implements FixtureGroupInterface
final class TestFixtures extends Fixture implements FixtureGroupInterface, DependentFixtureInterface
{
public function __construct(
private readonly UserPasswordHasherInterface $passwordHasher,
@@ -21,6 +23,11 @@ final class TestFixtures extends Fixture implements FixtureGroupInterface
return ['test'];
}
public function getDependencies(): array
{
return [KrtekFixtures::class];
}
public function load(ObjectManager $manager): void
{
$user = new User();
@@ -28,6 +35,39 @@ final class TestFixtures extends Fixture implements FixtureGroupInterface
$user->password = $this->passwordHasher->hashPassword($user, 'test1234');
$manager->persist($user);
$user = new User();
$user->email = 'krtek-admin@example.org';
$user->password = $this->passwordHasher->hashPassword($user, 'test1234');
$manager->persist($user);
$krtek = $this->getReference(KrtekFixtures::KRTEK_SEASON, Season::class);
$krtek->addOwner($user);
$anotherSeason = new Season();
$anotherSeason->name = 'Another Season';
$anotherSeason->seasonCode = 'bbbbb';
$manager->persist($anotherSeason);
$this->addReference('another-season', $anotherSeason);
$user = new User();
$user->email = 'user1@example.org';
$user->password = $this->passwordHasher->hashPassword($user, 'test1234');
$manager->persist($user);
$user->addSeason($anotherSeason);
$user = new User();
$user->email = 'user2@example.org';
$user->password = $this->passwordHasher->hashPassword($user, 'test1234');
$manager->persist($user);
$krtek->addOwner($user);
$anotherSeason->addOwner($user);
$manager->flush();
}
}