Alice bundle - how to use encoded password in yml fixture
You can put the hashed password in parameters, like this:
parameters: hash: $2y$13$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7uApp\Document\Trainee: trainee (template): password: <{hash}> ...
You must simply escape every $
with \$
for your example:
App\Document\Trainee: trainee (template): [...] password: '\$2y\$13\$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7u'
I suggest you to simply set a plaintext encoder in the test environment and set plaintext passwords in your fixtures.
First, switch to a plaintext password encoder in test
environnement:
# config/packages/test/security.yamlsecurity: encoders: App\Entity\User: algorithm: plaintext
Then in your fixture:
App\Entity\User: user1: username: user1@example.com password: 'password'
You can now use the plaintext password in your tests:
public function testLoginWithUsernameAndPassword(){ $response = static::createHttpClient()->request('POST', '/api/login', ['json' => [ 'username' => 'user1@example.com', 'password' => 'password' ]]); // assert $response}