Skip to content
Snippets Groups Projects
AppFixtures.php 811 B
Newer Older
<?php

namespace App\DataFixtures;

use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;

class AppFixtures extends Fixture
{
    private UserPasswordHasherInterface $passwordHasher;

    public function __construct(UserPasswordHasherInterface $passwordHasher)
    {
        $this->passwordHasher = $passwordHasher;
    }

    public function load(ObjectManager $manager): void
    {
        $user = new User;
        $user->setEmail("admin@test.step");
        $user->setDisplayName("Gary TEST");
        $user->setPassword($this->passwordHasher->hashPassword(
            $user,
            "password"
        ));
        $manager->persist($user);

        $manager->flush();
    }
}