Speedup symfony2 fixtures loading in tests with security.encoder_factory

136 views Asked by At

I create a lot of users (using FOSUserBundle user manager) in fixtures and load them on set up for tests. updatePassword() method takes a lot of time to execute, because it calculates hash (very expensive operation) for each user. How can I speedup it?

1

There are 1 answers

0
Christophe Coevoet On BEST ANSWER

What I do in my own project is that I change the password encoder for the test environment to something faster to compute than bcrypt.

The testsuite does not actually need to store password with the safety provided by bcrypt (the test database exists only on developer machines or on travis, and it uses weak passwords regularly anyway, and written in clear in the tests).
Using a simpler encoder makes test run faster if you create a lot of users.

It is very important to make such config change only in the config_test.yml file though. Real environments must use a safe password encoder.