Skip to content

Make email and password match in UserFactory - #1315

Merged
outdooracorn merged 1 commit into
mainfrom
update-user-factory
Nov 2, 2026
Merged

outdooracorn merged 1 commit into
mainfrom
update-user-factory

Conversation

@outdooracorn

@outdooracorn outdooracorn commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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 UserTest.php, which tests the model, 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.

Alternate locations considered:

  • tests/Database/Factories to match the namespace of factories
  • tests/Feature/Factories to fit in to Laravel's default test directory structure1

@outdooracorn
outdooracorn requested a review from tarrow October 28, 2026 00:07
@outdooracorn outdooracorn self-assigned this Oct 28, 2026
tarrow
tarrow previously approved these changes Oct 29, 2026

@tarrow tarrow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me; interesting you are logging into factory not seeder created users but I see no downside in this

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
@outdooracorn

outdooracorn commented Oct 30, 2026 •

Copy link
Copy Markdown
Member Author

interesting you are logging into factory not seeder created users but I see no downside in this

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.

@outdooracorn
outdooracorn requested a review from tarrow October 30, 2026 15:24
@outdooracorn
outdooracorn merged commit 8801062 into main Nov 2, 2026
4 checks passed
@outdooracorn
outdooracorn deleted the update-user-factory branch November 2, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants