- PHP 8.3 → 8.4 (Dockerfile + composer.json) - Symfony 7.0 → 8.0 (tous les composants symfony/*) - API Platform 3.x → 4.x : migration openapiContext → openapi: new Operation(...) - Doctrine DBAL 3 → 4 : suppression use_savepoints, replace prepare/executeQuery - Doctrine ORM 2.x → 3.x : ClassMetadataInfo → ClassMetadata, setParameters → setParameter - Doctrine Bundle 2.x → 3.x, Fixtures Bundle 3.x → 4.x - zenstruck/foundry 1.x → 2.x : ModelFactory → PersistentObjectFactory, getDefaults → defaults - phpmd/phpmd 2.x → 3.x-dev (seule version supportant Symfony 8) - phparkitect 0.3 → 0.8 : NotDependsOnTheseNamespaces prend un array - symfony/mercure-bundle 0.3 → 0.4, symfony/monolog-bundle 3 → 4 - Suppression de runtime/frankenphp-symfony (intégré nativement dans symfony/runtime 8) - worker.Caddyfile : suppression de APP_RUNTIME (détection automatique Symfony 8) - Routes errors.xml/wdt.xml/profiler.xml → .php (Symfony 8 supprime le XML) - Types::ARRAY → Types::JSON dans Entity/Manga.php (DBAL 4 retire array type) - Suppression de src/Schedule.php (doublon vide avec MonitoringSchedule) - Tests : hydra:Collection → Collection, hydra:member → member (API Platform 4)
77 lines
6.2 KiB
PHP
77 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Factory;
|
|
|
|
use App\Entity\User;
|
|
use App\Repository\UserRepository;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
|
|
use Zenstruck\Foundry\Persistence\RepositoryDecorator;
|
|
|
|
/**
|
|
* @extends PersistentObjectFactory<User>
|
|
*
|
|
* @method User create(array|callable $attributes = [])
|
|
* @method static User createOne(array $attributes = [])
|
|
* @method static User find(object|array|mixed $criteria)
|
|
* @method static User findOrCreate(array $attributes)
|
|
* @method static User first(string $sortedField = 'id')
|
|
* @method static User last(string $sortedField = 'id')
|
|
* @method static User random(array $attributes = [])
|
|
* @method static User randomOrCreate(array $attributes = [])
|
|
* @method static UserRepository&RepositoryDecorator repository()
|
|
* @method static list<User> all()
|
|
* @method static list<User> createMany(int $number, array|callable $attributes = [])
|
|
* @method static list<User> createSequence(iterable|callable $sequence)
|
|
* @method static list<User> findBy(array $attributes)
|
|
* @method static list<User> randomRange(int $min, int $max, array $attributes = [])
|
|
* @method static list<User> randomSet(int $number, array $attributes = [])
|
|
*/
|
|
final class UserFactory extends PersistentObjectFactory
|
|
{
|
|
public const array FIRST_NAMES = ['ALAIN', 'ALEXANDRE', 'ANDRÉ', 'ANNIE', 'ANTHONY', 'AUDREY', 'AURÉLIE', 'BERNARD', 'BRIGITTE', 'BRUNO', 'CATHERINE', 'CEDRIC', 'CHANTAL', 'CHRISTELLE', 'CHRISTIAN', 'CHRISTIANE', 'CHRISTINE', 'CHRISTOPHE', 'CLAUDE', 'CORINNE', 'CÉLINE', 'DANIEL', 'DANIELLE', 'DAVID', 'DENISE', 'DIDIER', 'DOMINIQUE', 'ELODIE', 'EMILIE', 'ENZO', 'ERIC', 'FABRICE', 'FLORENCE', 'FRANCK', 'FRANÇOISE', 'FRÉDÉRIC', 'GEORGES', 'GERMAINE', 'GUILLAUME', 'GUY', 'GÉRARD', 'HENRI', 'ISABELLE', 'JACQUELINE', 'JACQUES', 'JEAN', 'JEAN-CLAUDE', 'JEAN-PIERRE', 'JEANNE', 'JEANNINE', 'JEREMY', 'JEROME', 'JONATHAN', 'JOSEPH', 'JULIE', 'JULIEN', 'KARINE', 'KEVIN', 'LAETITIA', 'LAURA', 'LAURENCE', 'LAURENT', 'LOUIS', 'LUCAS', 'LÉA', 'MADELEINE', 'MANON', 'MARCEL', 'MARCELLE', 'MARGUERITE', 'MARIE', 'MARINE', 'MARTINE', 'MAURICE', 'MAXIME', 'MICHEL', 'MICHÈLE', 'MONIQUE', 'NATHALIE', 'NICOLAS', 'NICOLE', 'ODETTE', 'OLIVIER', 'PASCAL', 'PASCALE', 'PATRICIA', 'PATRICK', 'PAUL', 'PAULETTE', 'PHILIPPE', 'PIERRE', 'RENÉ', 'ROBERT', 'ROGER', 'ROMAIN', 'SANDRA', 'SANDRINE', 'SERGE', 'SOPHIE', 'STÉPHANE', 'STÉPHANIE', 'SUZANNE', 'SYLVIE', 'SÉBASTIEN', 'THIERRY', 'THOMAS', 'THÉO', 'VALÉRIE', 'VIRGINIE', 'VÉRONIQUE', 'YVETTE', 'YVONNE'];
|
|
public const array LAST_NAMES = ['Adam', 'Andre', 'Antoine', 'Arnaud', 'Aubert', 'Aubry', 'Bailly', 'Barbier', 'Baron', 'Barre', 'Barthelemy', 'Benard', 'Benoit', 'Berger', 'Bernard', 'Bertin', 'Bertrand', 'Besson', 'Blanc', 'Blanchard', 'Bonnet', 'Boucher', 'Bouchet', 'Boulanger', 'Bourgeois', 'Bouvier', 'Boyer', 'Breton', 'Brun', 'Brunet', 'Carlier', 'Caron', 'Carpentier', 'Carre', 'Charles', 'Charpentier', 'Chauvin', 'Chevalier', 'Chevallier', 'Clement', 'Colin', 'Collet', 'Collin', 'Cordier', 'Cousin', 'Da Silva', 'Daniel', 'David', 'Delaunay', 'Denis', 'Deschamps', 'Dubois', 'Dufour', 'Dumas', 'Dumont', 'Dupont', 'Dupuis', 'Dupuy', 'Durand', 'Duval', 'Etienne', 'Fabre', 'Faure', 'Fernandez', 'Fleury', 'Fontaine', 'Fournier', 'Francois', 'Gaillard', 'Garcia', 'Garnier', 'Gauthier', 'Gautier', 'Gay', 'Gerard', 'Germain', 'Gilbert', 'Gillet', 'Girard', 'Giraud', 'Gonzalez', 'Grondin', 'Guerin', 'Guichard', 'Guillaume', 'Guillot', 'Guyot', 'Hamon', 'Henry', 'Herve', 'Hoarau', 'Hubert', 'Huet', 'Humbert', 'Jacob', 'Jacquet', 'Jean', 'Joly', 'Julien', 'Klein', 'Lacroix', 'Lambert', 'Lamy', 'Langlois', 'Laporte', 'Laurent', 'Le Gall', 'Le Goff', 'Le Roux', 'Leblanc', 'Lebrun', 'Leclerc', 'Leclercq', 'Lecomte', 'Lefebvre', 'Lefevre', 'Leger', 'Legrand', 'Lejeune', 'Lemaire', 'Lemaitre', 'Lemoine', 'Leroux', 'Leroy', 'Leveque', 'Lopez', 'Louis', 'Lucas', 'Maillard', 'Mallet', 'Marchal', 'Marchand', 'Marechal', 'Marie', 'Martin', 'Martinez', 'Marty', 'Masson', 'Mathieu', 'Menard', 'Mercier', 'Meunier', 'Meyer', 'Michaud', 'Michel', 'Millet', 'Monnier', 'Moreau', 'Morel', 'Morin', 'Moulin', 'Muller', 'Nicolas', 'Noel', 'Olivier', 'Paris', 'Pasquier', 'Payet', 'Pelletier', 'Perez', 'Perret', 'Perrier', 'Perrin', 'Perrot', 'Petit', 'Philippe', 'Picard', 'Pichon', 'Pierre', 'Poirier', 'Poulain', 'Prevost', 'Remy', 'Renard', 'Renaud', 'Renault', 'Rey', 'Reynaud', 'Richard', 'Riviere', 'Robert', 'Robin', 'Roche', 'Rodriguez', 'Roger', 'Rolland', 'Rousseau', 'Roussel', 'Roux', 'Roy', 'Royer', 'Sanchez', 'Schmitt', 'Schneider', 'Simon', 'Tessier', 'Thomas', 'Vasseur', 'Vidal', 'Vincent', 'Weber'];
|
|
|
|
/**
|
|
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
|
|
*/
|
|
public function __construct(private readonly UserPasswordHasherInterface $passwordHasher)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public static function class(): string
|
|
{
|
|
return User::class;
|
|
}
|
|
|
|
/**
|
|
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
|
|
*/
|
|
protected function defaults(): array
|
|
{
|
|
return [
|
|
'email' => self::faker()->unique()->email(),
|
|
'password' => 'password',
|
|
'roles' => [],
|
|
'firstName' => self::faker()->randomElement(self::FIRST_NAMES),
|
|
'lastName' => self::faker()->randomElement(self::LAST_NAMES),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
|
|
*/
|
|
protected function initialize(): static
|
|
{
|
|
return $this
|
|
->afterInstantiate(function (User $user): void {
|
|
$user->setPassword($this->passwordHasher->hashPassword(
|
|
$user,
|
|
$user->getPassword()
|
|
));
|
|
})
|
|
;
|
|
}
|
|
}
|