wadakatu / laravel-factory-refactor
Refactor the style of factory call from helper to static method for Laravel 8.x.
Requires
- php: >=7.3
- illuminate/console: ^8.0|^9.0|^10.0
- illuminate/filesystem: ^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.24
- phpunit/phpunit: ^9.5
README
This package will help you to refactor the style of factory call from helper to static method for Laravel 8.x, 9.x, 10.x.
With this package, you can save plenty of time and focus on other important things.
Installation
You can install the package via composer:
composer require wadakatu/laravel-factory-refactor --dev
How to Use
To refactor the style of factory call from helper to static method, run the artisan command:
php artisan refactor:factory
Options
By default, all factory call under tests/
directory are the target of refactoring.
If you want to change the target directory, you can do that by using the --dir
option.
php artisan refactor:factory --dir tests/Feature
By default, Tests\\
namespace is the target of refactoring.
If you want to change the target namespace, you can do that by using the --namespace
option.
php artisan refactor:factory --dir app/Models --namespace App\\Models
Example
Before
factory(User::class)->make(); factory(App\Models\User::class)->make(); factory(User::class, 10)->make(); factory(App\Models\User::class, 10)->make(); factory($model)->make(); factory(User::class, $count['user'])->make();
After
User::factory()->make(); App\Models\User::factory()->make(); User::factory()->count(10)->make(); App\Models\User::factory()->count(10)->make(); $model::factory()->make(); User::factory()->count($count['user'])->make();
License
The MIT License (MIT). Please see license file for more information.