From 5b3884162ab702417af6d60e78391944a87298a4 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 20 Apr 2021 13:40:24 +0800 Subject: [PATCH] Adopt laravel 8.x model factory directory structure --- src/Generators/ModelFactoryGenerator.php | 6 +++++- tests/CrudApiMakeCommandTest.php | 4 ++-- tests/CrudMakeCommandTest.php | 4 ++-- tests/CrudSimpleMakeCommandTest.php | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Generators/ModelFactoryGenerator.php b/src/Generators/ModelFactoryGenerator.php index 046adf4..6be8b9a 100644 --- a/src/Generators/ModelFactoryGenerator.php +++ b/src/Generators/ModelFactoryGenerator.php @@ -12,7 +12,11 @@ class ModelFactoryGenerator extends BaseGenerator */ public function generate(string $type = 'full') { - $modelFactoryPath = $this->makeDirectory(database_path('factories')); + $modelFactoryPath = database_path('factories'); + if ($this->modelNames['model_path'] != 'Models') { + $modelFactoryPath .= '/'.$this->modelNames['model_path']; + } + $modelFactoryPath = $this->makeDirectory($modelFactoryPath); $modelFactoryClassPath = $modelFactoryPath.'/'.$this->modelNames['model_name'].'Factory.php'; if ($this->files->exists($modelFactoryClassPath)) { diff --git a/tests/CrudApiMakeCommandTest.php b/tests/CrudApiMakeCommandTest.php index 60a5360..dde115e 100644 --- a/tests/CrudApiMakeCommandTest.php +++ b/tests/CrudApiMakeCommandTest.php @@ -115,7 +115,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); $this->assertFileExists(app_path("Policies/{$modelName}Policy.php")); - $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); + $this->assertFileExists(database_path("factories/{$inputName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Api/Manage{$modelName}Test.php")); @@ -148,7 +148,7 @@ class CrudApiMakeCommandTest extends TestCase $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); - $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); + $this->assertFileExists(database_path("factories/{$inputName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php")); diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index d34c46f..7f4441e 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -128,7 +128,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); $this->assertFileExists(app_path("Policies/{$modelName}Policy.php")); - $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); + $this->assertFileExists(database_path("factories/{$inputName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php")); @@ -163,7 +163,7 @@ class CrudMakeCommandTest extends TestCase $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); - $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); + $this->assertFileExists(database_path("factories/{$inputName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php")); diff --git a/tests/CrudSimpleMakeCommandTest.php b/tests/CrudSimpleMakeCommandTest.php index de97f88..996c181 100644 --- a/tests/CrudSimpleMakeCommandTest.php +++ b/tests/CrudSimpleMakeCommandTest.php @@ -121,7 +121,7 @@ class CrudSimpleMakeCommandTest extends TestCase $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); $this->assertFileExists(app_path("Policies/{$modelName}Policy.php")); - $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); + $this->assertFileExists(database_path("factories/{$inputName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php")); @@ -154,7 +154,7 @@ class CrudSimpleMakeCommandTest extends TestCase $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); - $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); + $this->assertFileExists(database_path("factories/{$inputName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php"));