Repository navigation
Make email and password match in UserFactory - #1315
Conversation
tarrow
left a comment
There was a problem hiding this comment.
Seems fine to me; interesting you are logging into factory not seeder created users but I see no downside in this
5726536 to
f326b6b
Compare
Small quality of life change to make it easier to log in as users created with this factory (and that don't specify a password to use). Use a closure to set the password so that it works with both the default provided and overridden emails, and add tests to verify this. The test file is located at `tests/Feature/Models/UserFactoryTest.php` with the idea that it will sit next to the model's `UserTest.php` once all models and their tests are moved under a `*\Models` namespace. Given that factories are configured and accessed via its model, having the model and factory tests side-by-side seemed appropriate. Alternative locations considered: * `tests/Database/Factories` to match the namespace of factories * `tests/Feature/Factories` to fit in to Laravel's default test directory structure[1] [1]: https://laravel.com/framework/docs/11.x/testing
f326b6b to
af205a8
Compare
Haha yes, I wanted to test something locally while looking at some tests and they were the easiest users to use rather than creating up an identical setup manually. This change will also benefit seeders that create users without specifying a password. Writing this out made me think that I need to handle the case of users specifying an email address but not a password which the previous version didn't do. I have now pushed a change which is now more robust. I also added some tests to prove this works as intended. |
Small quality of life change to make it easier to log in as users created with this factory (and that don't specify a password to use).
Use a closure to set the password so that it works with both the default provided and overridden emails, and add tests to verify this.
The test file is located at
tests/Feature/Models/UserFactoryTest.phpwith the idea that it will sit next toUserTest.php, which tests the model, once all models and their tests are moved under a*\Modelsnamespace. Given that factories are configured and accessed via its model, having the model and factory tests side-by-side seemed appropriate.Alternate locations considered:
tests/Database/Factoriesto match the namespace of factoriestests/Feature/Factoriesto fit in to Laravel's default test directory structure1