From 8d444cdc4874b0a48d7e49ae085df77d0aba314f Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 14 Oct 2024 11:03:19 -0400 Subject: [PATCH] Replace HasFactory with HasDomainFactory. --- src/Commands/DomainModelMakeCommand.php | 26 ++++++++++++++----------- tests/Generator/Model/MakeTest.php | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Commands/DomainModelMakeCommand.php b/src/Commands/DomainModelMakeCommand.php index 9f798e0..b623b0b 100644 --- a/src/Commands/DomainModelMakeCommand.php +++ b/src/Commands/DomainModelMakeCommand.php @@ -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; } @@ -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()), ]); diff --git a/tests/Generator/Model/MakeTest.php b/tests/Generator/Model/MakeTest.php index f465263..84bca9f 100644 --- a/tests/Generator/Model/MakeTest.php +++ b/tests/Generator/Model/MakeTest.php @@ -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) {