-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[11.x] Feat: remove HasFactory in model when not required #53104
[11.x] Feat: remove HasFactory in model when not required #53104
Conversation
Something is wrong with failing tests. |
how common is it to not have a factory for a model? I don't think I've ever not made one. |
if "not writing tests" is the reason behind it, maybe we don't want to make it easier on them. lol |
@browner12 Agreed! Btw main reason behind this PR is these 2 comments! |
I feel fine with these changes as you can still run |
Convert to draft as tests are failing on Windows. |
@@ -263,7 +263,7 @@ protected function buildFactoryReplacements() | |||
$replacements['{{ factoryImport }}'] = 'use Illuminate\Database\Eloquent\Factories\HasFactory;'; | |||
} else { | |||
$replacements['{{ factoryCode }}'] = '//'; | |||
$replacements["\n{{ factoryImport }}"] = ''; | |||
$replacements["{{ factoryImport }}\n"] = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code does not pass the tests on the local Windows machine. (but in workflow, it passed).
On Windows \r\n
is used as a new line and in UNIX \n
is used as a new line that's why I used PHP_EOL
to specify it and it was passing in the Windows machine.
But as you can see in the failing test in workflow, it is \n
instead of \r\n
so I doubt if it is running on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you test againts \r\n
, \r
and \n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
268289c
to
641b1d5
Compare
I added replacements for both $replacements["{{ factoryImport }}\n"] = '';
$replacements["{{ factoryImport }}\r\n"] = ''; But ideally, it should pass with $replacements['{{ factoryImport }}'.PHP_EOL] = ''; |
A few days ago, I made a PR to improve the
make:model
command to include the factory genericPHPDoc
when needed. Based on comments from @Jubeki and @jasonmccreary, it seems that it would be cool to removeHasFactory
if we are not generating a factory at all.examples:
Command
Output
Command
php artisan make:model Comment -f
Output