Closed Lydnasty closed 1 year ago
I've found the issue.
The problem was this piece of code in my UserFactory.
protected function initialize(): self
{
return $this->afterInstantiate(function (User $user) {
$user->setPassword($this->passwordHasher->hashPassword($user, $user->getPassword()));
});
}
Removing it solved the performance problem. I'll have to find another way to do it.
Hi @Lydnasty
I think you should change the password hasher algorithm used in your test
from https://symfony.com/doc/current/security/passwords.html#configuring-a-password-hasher :
Hashing passwords is resource intensive and takes time in order to generate secure password hashes. In general, this makes your password hashing more secure. In tests however, secure hashes are not important, so you can change the password hasher configuration in test environment to run tests faster:
flushing for every entity created.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#delay-flush can help here.
So I'm trying to migrate my fixtures from Doctrine to foundry to have a cleaner code, but the execution time is multiplied by 200 probably because it's flushing for every entity created.
This is my original code:
And this is the code I using foundry:
I've tried using Factory::delayFlush but I'm getting the same execution time, probably because I'm doing something wrong:
Can you tell me what I'm doing wrong please?