Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/Generators/AbstractTestsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ protected function getMockModel($model): array
return [];
}

$modelClass = $this->getModelClass($model);
$factory = $modelClass::factory();
$factoryNamespace = "{$this->getOrCreateNamespace('factories')}\\{$model}Factory";
$factory = $factoryNamespace::new();

return $factory
->make()
Expand Down
1 change: 1 addition & 0 deletions src/Generators/FactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function generate(): void
'namespace' => $this->getOrCreateNamespace('factories'),
'entity' => $this->model,
'fields' => $this->prepareFields(),
'modelNamespace' => $this->getOrCreateNamespace('models'),
]);

$this->saveClass('factories', "{$this->model}Factory", $factoryContent);
Expand Down
3 changes: 3 additions & 0 deletions stubs/factory.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factories\Factory;
use {{$modelNamespace}}\{{$entity}};

class {{$entity}}Factory extends Factory
{
protected $model = {{$entity}}::class;

public function definition(): array
{
@if(!empty($fields))
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/FactoryGeneratorTest/post_factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Post;

class PostFactory extends Factory
{
protected $model = Post::class;

public function definition(): array
{
$faker = app(Faker::class);
Expand Down
Loading