Skip to content

Commit

Permalink
Replace HasFactory with HasDomainFactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertey committed Oct 14, 2024
1 parent c55cd08 commit 8d444cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/Commands/DomainModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,26 @@ protected function buildClass($name)
{
$stub = parent::buildClass($name);

$replacements = [
'use Illuminate\Database\Eloquent\Factories\HasFactory;' => "use Lunarstorm\LaravelDDD\Factories\HasDomainFactory as HasFactory;",
];

if ($baseModel = $this->getBaseModel()) {
$baseModelClass = class_basename($baseModel);

$replacements = [
'use Illuminate\Database\Eloquent\Model;' => "use {$baseModel};",
$replacements = array_merge($replacements, [
'extends Model' => "extends {$baseModelClass}",
];
'use Illuminate\Database\Eloquent\Model;' => "use {$baseModel};",
]);
}

$stub = str_replace(
array_keys($replacements),
array_values($replacements),
$stub
);
$stub = str_replace(
array_keys($replacements),
array_values($replacements),
$stub
);

$stub = $this->sortImports($stub);
}
$stub = $this->sortImports($stub);

return $stub;
}
Expand All @@ -59,7 +63,7 @@ protected function createFactory()
$factory = Str::studly($this->argument('name'));

$this->call(DomainFactoryMakeCommand::class, [
'name' => $factory.'Factory',
'name' => $factory . 'Factory',
'--domain' => $this->domain->dotName,
'--model' => $this->qualifyClass($this->getNameInput()),
]);
Expand Down
3 changes: 2 additions & 1 deletion tests/Generator/Model/MakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
config('ddd.namespaces.model'),
]);

expect(file_get_contents($expectedModelPath))->toContain("namespace {$expectedNamespace};");
expect(file_get_contents($expectedModelPath))
->toContain("namespace {$expectedNamespace};");
})->with('domainPaths');

it('can generate a domain model with factory', function ($domainPath, $domainRoot, $domainName, $subdomain) {
Expand Down

0 comments on commit 8d444cd

Please sign in to comment.