[8.x] Make Database Factory macroable #36380
Merged
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.
My company is looking to upgrade to Laravel 8 soon, and while doing some due diligence, we noticed that we were going to have an issue with how we are currently using factory states and how they are handled in L8. While we're looking forward to using the new class-based factories, we have hundreds of states, thousands of tests, and a home-grown factory/state builder, which is used to create complex user stories. These references are using the string-based versions of states but accumulated over all of the builder calls and finally executed with the L7
->states(...)
method call.It would be a huge undertaking to make adjustments to the builder and delay the upgrade to L8. So, I'd like to add a macro to get the
states()
method back onto the database factory class. This way, we'd be able to temporarily leverage the macro and delete it when we're done with the changes we need to make to our builder. We might have to add some other macros as well, but this is to be determined.The initial idea is to do something like this for the
states()
method.