-
-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laravel 8 factory support #861
Conversation
Thanks for getting this going, I tried it out in our project.
Works beautifully.
Does not work for me yet. |
be4a6dc
to
f401a14
Compare
Yeah, I forgot to write it in the description. Now that the I'll write this in release notes/changelog or upgrade guide before merging. |
Sounds reasonable. Is there a way to infer this type when coming from a |
No. When you extend a generic class you only have 2 options. Either use |
Is there a way to run PHP 8 tests only on PHP 8? |
It works fine when using I thought it would have to work, given from what I have experienced with inferred types of I am not sure I agree with PHPStan here, if that is where the limitation is coming from. Creating a subclass of a generic class does not necessarily erase its generic-ness. |
c138859
to
f480a6c
Compare
@szepeviktor Do you mean Laravel 8? Because we don't have any PHP 8 tests. For Laravel 8 yeah we are trying to run it on just Laravel 8, but seems it does not work exactly the way we wanted. @spawnia It does not erase the genericness. If a class has a |
Yes. |
My language was not that clear, and generic-ness is not a well-defined term. Having to provide an argument for the generic type parameter is what I deem erasure of the generic-ness. Any subclass extending from a generic class is no longer a generic class, unless the generic is redefined. I would think that when no type argument is provided, the generic keeps being generic. |
a2efb00
to
6cb4ae5
Compare
I think this is ready. I'll test it in some projects of mine. And maybe clean it a little more. Then we can merge 👍🏽 |
tests/Features/Laravel8/Application/database/factories/UserFactory.php
Outdated
Show resolved
Hide resolved
22679b5
to
bf09e20
Compare
380c898
to
82b2f3a
Compare
Closes #661
This PR adds support for Laravel 8 factories.
User::factory()
would returnUserFactory
User::factory()->createOne()
would returnUser
create
method. It can either return collection of models, or single model. And this is decided by thecount()
method. This kind of fluent calls are hard to keep track with PHPStan.I will add support for relations later (
has{Relation}
andfor{Relation}
method calls), I'm opening the PR now so if anyone wants to try over the weekend they could do so. I'd appreciate any feedback if anyone tries.