Include all user table columns in the UserFactory #1168
Merged
+4
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Jetstream creates migrations to add new columns in the user table, even if Jetstream isn't configured to use teams or profile pictures or 2FA. But because these fields are missing from the
UserFactory
that Jetstream installs, the default Jetstream tests will fail when using theModel::preventAccessingMissingAttributes()
feature of model strictness.These test failures are extremely unexpected when you've followed the happy path of Laravel, Jetstream, and then merely enabled model strictness. And the failures are not obvious. People who are new to Laravel seem likely to be very confused by these errors and might be dissuaded from using model strictness (and I do think people should be encouraged to use model strictness).
The Fix
Adding these missing fields to the factory prevents these exceptions, and allows the tests to pass.
Alternatives Considered
An alternative approach could be doing feature detection to alter the return of the
UserFactory
definition, and also doing feature detection in the templates, such that user data items for unused features aren't accessed. That seems a lot more complicated, when we could just add the default-null columns to the factory and be done.fixes #1164