Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected function buildFactoryReplacements()
{
$replacements = [];

if ($this->option('factory')) {
if ($this->option('factory') || $this->option('all')) {
$modelPath = str($this->argument('name'))->studly()->replace('/', '\\')->toString();

$factoryNamespace = '\\Database\\Factories\\'.$modelPath.'Factory';
Expand Down
27 changes: 27 additions & 0 deletions tests/Integration/Generators/ModelMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ModelMakeCommandTest extends TestCase
'app/Http/Controllers/BarController.php',
'database/factories/FooFactory.php',
'database/factories/Foo/BarFactory.php',
'database/migrations/*_create_foos_table.php',
'database/seeders/FooSeeder.php',
'tests/Feature/Models/FooTest.php',
];
Expand Down Expand Up @@ -144,6 +145,32 @@ public function testItCanGenerateModelFileWithFactoryOptionForDeepFolder()
$this->assertFilenameNotExists('database/seeders/Foo/BarSeeder.php');
}

public function testItGeneratesModelWithHasFactoryTraitWhenUsingAllOption()
{
$this->artisan('make:model', ['name' => 'Foo', '--all' => true])
->expectsQuestion('A App\Models\Foo model does not exist. Do you want to generate it?', false)
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Models;',
'use Illuminate\Database\Eloquent\Factories\HasFactory;',
'use Illuminate\Database\Eloquent\Model;',
'class Foo extends Model',
'/** @use HasFactory<\Database\Factories\FooFactory> */',
'use HasFactory;',
], 'app/Models/Foo.php');

$this->assertFileNotContains([
'{{ factoryImport }}',
'{{ factory }}',
], 'app/Models/Foo.php');

$this->assertFilenameExists('app/Http/Controllers/FooController.php');
$this->assertFilenameExists('database/factories/FooFactory.php');
$this->assertFilenameExists('database/seeders/FooSeeder.php');
$this->assertMigrationFileExists('create_foos_table.php');
}

public function testItCanGenerateModelFileWithMigrationOption()
{
$this->artisan('make:model', ['name' => 'Foo', '--migration' => true])
Expand Down