From 15fa99dce87d5359f159d0ac3c766e14cfd19656 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Mon, 16 Oct 2017 21:27:27 +0800 Subject: [PATCH] Add full model name modelNames attribute on CrudMake --- src/CrudMake.php | 12 +++++++++++- src/stubs/controller.model.stub | 6 +++--- src/stubs/model-factory.stub | 2 +- src/stubs/test-feature.stub | 2 +- src/stubs/test-unit.stub | 2 +- tests/CrudMakeCommandTest.php | 9 ++++++++- tests/Generators/ControllerGeneratorTest.php | 6 +++--- tests/Generators/FeatureTestGeneratorTest.php | 2 +- tests/Generators/ModelFactoryGeneratorTest.php | 2 +- tests/Generators/ModelTestGeneratorTest.php | 2 +- tests/TestCase.php | 2 ++ 11 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/CrudMake.php b/src/CrudMake.php index 9ccc543..1d491e9 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -26,7 +26,7 @@ class CrudMake extends Command * * @var array */ - public $stubModelNames = ['Masters', 'Master', 'masters', 'master', 'mstrCollections', 'singleMstr']; + public $stubModelNames; /** * Construct CrudMake class @@ -37,6 +37,15 @@ class CrudMake extends Command parent::__construct(); $this->files = $files; + $this->stubModelNames = [ + 'full_model_name' => 'fullMstr', + 'plural_model_name' => 'Masters', + 'model_name' => 'Master', + 'table_name' => 'masters', + 'lang_name' => 'master', + 'collection_model_var_name' => 'mstrCollections', + 'single_model_var_name' => 'singleMstr', + ]; } /** @@ -91,6 +100,7 @@ class CrudMake extends Command $plural_model_name = str_plural($model_name); return $this->modelNames = [ + 'full_model_name' => 'App\\'.$model_name, 'plural_model_name' => $plural_model_name, 'model_name' => $model_name, 'table_name' => snake_case($plural_model_name), diff --git a/src/stubs/controller.model.stub b/src/stubs/controller.model.stub index 35a0881..0832ad7 100644 --- a/src/stubs/controller.model.stub +++ b/src/stubs/controller.model.stub @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Master; +use fullMstr; use Illuminate\Http\Request; class MastersController extends Controller @@ -48,7 +48,7 @@ class MastersController extends Controller * Update the specified singleMstr in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Master $singleMstr + * @param \fullMstr $singleMstr * @return \Illuminate\Http\Response */ public function update(Request $request, Master $singleMstr) @@ -68,7 +68,7 @@ class MastersController extends Controller /** * Remove the specified singleMstr from storage. * - * @param \App\Master $singleMstr + * @param \fullMstr $singleMstr * @return \Illuminate\Http\Response */ public function destroy(Master $singleMstr) diff --git a/src/stubs/model-factory.stub b/src/stubs/model-factory.stub index 4af10c6..a3c8790 100644 --- a/src/stubs/model-factory.stub +++ b/src/stubs/model-factory.stub @@ -1,6 +1,6 @@ define(Master::class, function (Faker $faker) { diff --git a/src/stubs/test-feature.stub b/src/stubs/test-feature.stub index f1441d4..3603193 100644 --- a/src/stubs/test-feature.stub +++ b/src/stubs/test-feature.stub @@ -2,7 +2,7 @@ namespace Tests\Feature; -use App\Master; +use fullMstr; use Tests\BrowserKitTest as TestCase; use Illuminate\Foundation\Testing\DatabaseMigrations; diff --git a/src/stubs/test-unit.stub b/src/stubs/test-unit.stub index 60123cf..c501773 100644 --- a/src/stubs/test-unit.stub +++ b/src/stubs/test-unit.stub @@ -2,7 +2,7 @@ namespace Tests\Unit\Models; -use App\Master; +use fullMstr; use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\TestCase; diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index bf7a85b..36f3e15 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -13,7 +13,13 @@ class CrudMakeCommandTest extends TestCase $crudMaker = app(CrudMake::class); $this->assertEquals([ - 'Masters', 'Master', 'masters', 'master', 'mstrCollections', 'singleMstr', + 'full_model_name' => 'fullMstr', + 'plural_model_name' => 'Masters', + 'model_name' => 'Master', + 'table_name' => 'masters', + 'lang_name' => 'master', + 'collection_model_var_name' => 'mstrCollections', + 'single_model_var_name' => 'singleMstr', ], $crudMaker->stubModelNames); } @@ -23,6 +29,7 @@ class CrudMakeCommandTest extends TestCase $crudMaker = app(CrudMake::class); $this->assertEquals([ + 'full_model_name' => 'App\Category', 'plural_model_name' => 'Categories', 'model_name' => 'Category', 'table_name' => 'categories', diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php index 7b68ea3..d3069f4 100644 --- a/tests/Generators/ControllerGeneratorTest.php +++ b/tests/Generators/ControllerGeneratorTest.php @@ -16,7 +16,7 @@ class ControllerGeneratorTest extends TestCase namespace App\Http\Controllers; -use App\\{$this->model_name}; +use {$this->full_model_name}; use Illuminate\Http\Request; class {$this->plural_model_name}Controller extends Controller @@ -62,7 +62,7 @@ class {$this->plural_model_name}Controller extends Controller * Update the specified {$this->single_model_var_name} in storage. * * @param \Illuminate\Http\Request \$request - * @param \App\\{$this->model_name} \${$this->single_model_var_name} + * @param \\{$this->full_model_name} \${$this->single_model_var_name} * @return \Illuminate\Http\Response */ public function update(Request \$request, {$this->model_name} \${$this->single_model_var_name}) @@ -82,7 +82,7 @@ class {$this->plural_model_name}Controller extends Controller /** * Remove the specified {$this->single_model_var_name} from storage. * - * @param \App\\{$this->model_name} \${$this->single_model_var_name} + * @param \\{$this->full_model_name} \${$this->single_model_var_name} * @return \Illuminate\Http\Response */ public function destroy({$this->model_name} \${$this->single_model_var_name}) diff --git a/tests/Generators/FeatureTestGeneratorTest.php b/tests/Generators/FeatureTestGeneratorTest.php index 82f1d7f..272352d 100644 --- a/tests/Generators/FeatureTestGeneratorTest.php +++ b/tests/Generators/FeatureTestGeneratorTest.php @@ -53,7 +53,7 @@ abstract class BrowserKitTest extends BaseTestCase namespace Tests\Feature; -use App\\{$this->model_name}; +use {$this->full_model_name}; use Tests\BrowserKitTest as TestCase; use Illuminate\Foundation\Testing\DatabaseMigrations; diff --git a/tests/Generators/ModelFactoryGeneratorTest.php b/tests/Generators/ModelFactoryGeneratorTest.php index 43ffbdd..2661d57 100644 --- a/tests/Generators/ModelFactoryGeneratorTest.php +++ b/tests/Generators/ModelFactoryGeneratorTest.php @@ -15,7 +15,7 @@ class ModelFactoryGeneratorTest extends TestCase $this->assertFileExists($modelFactoryPath); $modelFactoryContent = "model_name}; +use {$this->full_model_name}; use Faker\Generator as Faker; \$factory->define({$this->model_name}::class, function (Faker \$faker) { diff --git a/tests/Generators/ModelTestGeneratorTest.php b/tests/Generators/ModelTestGeneratorTest.php index 41f3ab4..a5ece64 100644 --- a/tests/Generators/ModelTestGeneratorTest.php +++ b/tests/Generators/ModelTestGeneratorTest.php @@ -16,7 +16,7 @@ class ModelTestGeneratorTest extends TestCase namespace Tests\Unit\Models; -use App\\{$this->model_name}; +use {$this->full_model_name}; use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\TestCase; diff --git a/tests/TestCase.php b/tests/TestCase.php index 0479d00..c44a156 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,7 @@ use Orchestra\Testbench\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { + protected $full_model_name; protected $model_name; protected $plural_model_name; protected $table_name; @@ -18,6 +19,7 @@ abstract class TestCase extends BaseTestCase parent::setUp(); $this->model_name = 'PaymentMethod'; + $this->full_model_name = 'App\\'.$this->model_name; $this->plural_model_name = str_plural($this->model_name); $this->table_name = snake_case($this->plural_model_name); $this->lang_name = snake_case($this->model_name);