From a31ee6ea6bc22478c9e2daef3b6133296fd87a76 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 23 Aug 2018 08:26:39 +0800 Subject: [PATCH] Change controller name convention to singular --- src/Generators/ControllerGenerator.php | 8 ++++---- src/Generators/RouteGenerator.php | 6 +++--- src/stubs/controllers/api.stub | 2 +- src/stubs/controllers/full.stub | 2 +- src/stubs/controllers/simple.stub | 2 +- src/stubs/routes/api.stub | 2 +- src/stubs/routes/web.stub | 2 +- tests/CrudApiMakeCommandTest.php | 10 +++++----- tests/CrudMakeCommandTest.php | 8 ++++---- tests/CrudSimpleMakeCommandTest.php | 8 ++++---- tests/Generators/Api/ApiControllerGeneratorTest.php | 6 +++--- tests/Generators/Api/RouteApiGeneratorTest.php | 4 ++-- tests/Generators/FullControllerGeneratorTest.php | 18 +++++++++--------- tests/Generators/RouteWebGeneratorTest.php | 4 ++-- .../Simple/SimpleControllerGeneratorTest.php | 18 +++++++++--------- 15 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index 87c2903..c8de52c 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -12,7 +12,7 @@ class ControllerGenerator extends BaseGenerator */ public function generate(string $type = 'full') { - $pluralModelName = $this->modelNames['plural_model_name']; + $modelName = $this->modelNames['model_name']; $parentControllerDirectory = ''; if (!is_null($this->command->option('parent'))) { $parentControllerDirectory = '/'.$this->command->option('parent'); @@ -23,15 +23,15 @@ class ControllerGenerator extends BaseGenerator } $controllerPath = $this->makeDirectory(app_path('Http/Controllers'.$parentControllerDirectory)); - $controllerPath = $controllerPath.'/'.$pluralModelName.'Controller.php'; + $controllerPath = $controllerPath.'/'.$modelName.'Controller.php'; $this->generateFile($controllerPath, $this->getContent('controllers/'.$type)); if ($this->isForApi()) { - $pluralModelName = 'Api/'.$pluralModelName; + $modelName = 'Api/'.$modelName; } - $this->command->info($pluralModelName.'Controller generated.'); + $this->command->info($modelName.'Controller generated.'); } /** diff --git a/src/Generators/RouteGenerator.php b/src/Generators/RouteGenerator.php index 649aa06..38ee1a5 100644 --- a/src/Generators/RouteGenerator.php +++ b/src/Generators/RouteGenerator.php @@ -29,11 +29,11 @@ class RouteGenerator extends BaseGenerator $webRouteFileContent = $this->replaceStubString($stub); if (!is_null($parentName = $this->command->option('parent'))) { - $pluralModelName = $this->modelNames['plural_model_name']; + $modelName = $this->modelNames['model_name']; $webRouteFileContent = str_replace( - $pluralModelName.'Controller', - $parentName.'\\'.$pluralModelName.'Controller', + $modelName.'Controller', + $parentName.'\\'.$modelName.'Controller', $webRouteFileContent ); } diff --git a/src/stubs/controllers/api.stub b/src/stubs/controllers/api.stub index fa868b8..39918f3 100644 --- a/src/stubs/controllers/api.stub +++ b/src/stubs/controllers/api.stub @@ -6,7 +6,7 @@ use fullMstr; use App\Http\Controllers\Controller; use Illuminate\Http\Request; -class MastersController extends Controller +class MasterController extends Controller { /** * Get a listing of the singleMstr. diff --git a/src/stubs/controllers/full.stub b/src/stubs/controllers/full.stub index 2651ebb..dd57512 100644 --- a/src/stubs/controllers/full.stub +++ b/src/stubs/controllers/full.stub @@ -5,7 +5,7 @@ namespace App\Http\Controllers; use fullMstr; use Illuminate\Http\Request; -class MastersController extends Controller +class MasterController extends Controller { /** * Display a listing of the singleMstr. diff --git a/src/stubs/controllers/simple.stub b/src/stubs/controllers/simple.stub index 89ff9d7..8815a8c 100644 --- a/src/stubs/controllers/simple.stub +++ b/src/stubs/controllers/simple.stub @@ -5,7 +5,7 @@ namespace App\Http\Controllers; use fullMstr; use Illuminate\Http\Request; -class MastersController extends Controller +class MasterController extends Controller { /** * Display a listing of the singleMstr. diff --git a/src/stubs/routes/api.stub b/src/stubs/routes/api.stub index 3da067e..f091613 100644 --- a/src/stubs/routes/api.stub +++ b/src/stubs/routes/api.stub @@ -2,4 +2,4 @@ /* * Masters Endpoints */ -Route::middleware('auth:api')->resource('masters', 'Api\MastersController')->names('api.masters'); +Route::middleware('auth:api')->resource('masters', 'Api\MasterController')->names('api.masters'); diff --git a/src/stubs/routes/web.stub b/src/stubs/routes/web.stub index 0a38be8..fd9c2aa 100644 --- a/src/stubs/routes/web.stub +++ b/src/stubs/routes/web.stub @@ -2,4 +2,4 @@ /* * Masters Routes */ -Route::resource('masters', 'MastersController'); +Route::resource('masters', 'MasterController'); diff --git a/tests/CrudApiMakeCommandTest.php b/tests/CrudApiMakeCommandTest.php index b013034..f7f13be 100644 --- a/tests/CrudApiMakeCommandTest.php +++ b/tests/CrudApiMakeCommandTest.php @@ -14,7 +14,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($this->model_name.'.php')); - $this->assertFileExists(app_path("Http/Controllers/Api/{$this->plural_model_name}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/Api/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); $this->assertFileExists($migrationFilePath); @@ -41,7 +41,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertContains("We will use existing {$this->model_name} model.", app(Kernel::class)->output()); $this->assertFileExists(app_path($this->model_name.'.php')); - $this->assertFileExists(app_path("Http/Controllers/Api/{$this->plural_model_name}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/Api/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); $this->assertFileNotExists($migrationFilePath); @@ -65,7 +65,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertContains("We will use existing Problem model.", app(Kernel::class)->output()); $this->assertFileExists(app_path('Entities/Projects/Problem.php')); - $this->assertFileExists(app_path("Http/Controllers/Api/ProblemsController.php")); + $this->assertFileExists(app_path("Http/Controllers/Api/ProblemController.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_problems_table.php'); $this->assertFileNotExists($migrationFilePath); @@ -101,7 +101,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); - $this->assertFileExists(app_path("Http/Controllers/Api/{$pluralModelName}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/Api/{$modelName}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); @@ -134,7 +134,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); - $this->assertFileExists(app_path("Http/Controllers/Api/{$parentName}/{$pluralModelName}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/Api/{$parentName}/{$modelName}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index 8199af6..c43a202 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -14,7 +14,7 @@ class CrudMakeCommandTest extends TestCase $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($this->model_name.'.php')); - $this->assertFileExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); $this->assertFileExists($migrationFilePath); @@ -43,7 +43,7 @@ class CrudMakeCommandTest extends TestCase $this->assertContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($this->model_name.'.php')); - $this->assertFileNotExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php")); + $this->assertFileNotExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); $this->assertFileNotExists($migrationFilePath); @@ -110,7 +110,7 @@ class CrudMakeCommandTest extends TestCase $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); - $this->assertFileExists(app_path("Http/Controllers/{$pluralModelName}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$modelName}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); @@ -145,7 +145,7 @@ class CrudMakeCommandTest extends TestCase $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); - $this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$pluralModelName}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$modelName}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); diff --git a/tests/CrudSimpleMakeCommandTest.php b/tests/CrudSimpleMakeCommandTest.php index ee73b18..d0eb307 100644 --- a/tests/CrudSimpleMakeCommandTest.php +++ b/tests/CrudSimpleMakeCommandTest.php @@ -14,7 +14,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($this->model_name.'.php')); - $this->assertFileExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); $this->assertFileExists($migrationFilePath); @@ -41,7 +41,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($this->model_name.'.php')); - $this->assertFileNotExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php")); + $this->assertFileNotExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); $this->assertFileNotExists($migrationFilePath); @@ -104,7 +104,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); - $this->assertFileExists(app_path("Http/Controllers/{$pluralModelName}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$modelName}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); @@ -137,7 +137,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); - $this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$pluralModelName}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$modelName}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); diff --git a/tests/Generators/Api/ApiControllerGeneratorTest.php b/tests/Generators/Api/ApiControllerGeneratorTest.php index 38bcd62..bb0a17f 100644 --- a/tests/Generators/Api/ApiControllerGeneratorTest.php +++ b/tests/Generators/Api/ApiControllerGeneratorTest.php @@ -11,7 +11,7 @@ class ApiControllerGeneratorTest extends TestCase { $this->artisan('make:crud-api', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertFileExists(app_path("Http/Controllers/Api/{$this->plural_model_name}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/Api/{$this->model_name}Controller.php")); $ctrlClassContent = "full_model_name}; use App\Http\Controllers\Controller; use Illuminate\Http\Request; -class {$this->plural_model_name}Controller extends Controller +class {$this->model_name}Controller extends Controller { /** * Get a listing of the {$this->single_model_var_name}. @@ -116,6 +116,6 @@ class {$this->plural_model_name}Controller extends Controller } } "; - $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/Api/{$this->plural_model_name}Controller.php"))); + $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/Api/{$this->model_name}Controller.php"))); } } diff --git a/tests/Generators/Api/RouteApiGeneratorTest.php b/tests/Generators/Api/RouteApiGeneratorTest.php index 7b15e0d..9e1aa4b 100644 --- a/tests/Generators/Api/RouteApiGeneratorTest.php +++ b/tests/Generators/Api/RouteApiGeneratorTest.php @@ -18,7 +18,7 @@ class RouteApiGeneratorTest extends TestCase /* * {$this->plural_model_name} Endpoints */ -Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\{$this->plural_model_name}Controller')->names('api.{$this->table_name}'); +Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\{$this->model_name}Controller')->names('api.{$this->table_name}'); "; $this->assertEquals($routeApiFileContent, file_get_contents($routeApiPath)); } @@ -35,7 +35,7 @@ Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\{$this->plu /* * {$this->plural_model_name} Endpoints */ -Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\Projects\\{$this->plural_model_name}Controller')->names('api.{$this->table_name}'); +Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\Projects\\{$this->model_name}Controller')->names('api.{$this->table_name}'); "; $this->assertEquals($routeApiFileContent, file_get_contents($routeApiPath)); } diff --git a/tests/Generators/FullControllerGeneratorTest.php b/tests/Generators/FullControllerGeneratorTest.php index e16c391..89723b6 100644 --- a/tests/Generators/FullControllerGeneratorTest.php +++ b/tests/Generators/FullControllerGeneratorTest.php @@ -11,7 +11,7 @@ class FullControllerGeneratorTest extends TestCase { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertFileExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); $ctrlClassContent = "full_model_name}; use Illuminate\Http\Request; -class {$this->plural_model_name}Controller extends Controller +class {$this->model_name}Controller extends Controller { /** * Display a listing of the {$this->single_model_var_name}. @@ -136,7 +136,7 @@ class {$this->plural_model_name}Controller extends Controller } } "; - $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/{$this->plural_model_name}Controller.php"))); + $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/{$this->model_name}Controller.php"))); } /** @test */ @@ -144,7 +144,7 @@ class {$this->plural_model_name}Controller extends Controller { $this->artisan('make:crud', ['name' => 'Entities/References/Category', '--no-interaction' => true]); - $this->assertFileExists(app_path("Http/Controllers/CategoriesController.php")); + $this->assertFileExists(app_path("Http/Controllers/CategoryController.php")); $ctrlClassContent = "assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/CategoriesController.php"))); + $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/CategoryController.php"))); } /** @test */ @@ -277,7 +277,7 @@ class CategoriesController extends Controller { $this->artisan('make:crud', ['name' => 'Entities/References/Category', '--parent' => 'Projects', '--no-interaction' => true]); - $this->assertFileExists(app_path("Http/Controllers/Projects/CategoriesController.php")); + $this->assertFileExists(app_path("Http/Controllers/Projects/CategoryController.php")); $ctrlClassContent = "assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/Projects/CategoriesController.php"))); + $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/Projects/CategoryController.php"))); } } diff --git a/tests/Generators/RouteWebGeneratorTest.php b/tests/Generators/RouteWebGeneratorTest.php index af597b9..8901b1e 100644 --- a/tests/Generators/RouteWebGeneratorTest.php +++ b/tests/Generators/RouteWebGeneratorTest.php @@ -18,7 +18,7 @@ class RouteWebGeneratorTest extends TestCase /* * {$this->plural_model_name} Routes */ -Route::resource('{$this->table_name}', '{$this->plural_model_name}Controller'); +Route::resource('{$this->table_name}', '{$this->model_name}Controller'); "; $this->assertEquals($routeWebFileContent, file_get_contents($routeWebPath)); } @@ -35,7 +35,7 @@ Route::resource('{$this->table_name}', '{$this->plural_model_name}Controller'); /* * {$this->plural_model_name} Routes */ -Route::resource('{$this->table_name}', 'Projects\\{$this->plural_model_name}Controller'); +Route::resource('{$this->table_name}', 'Projects\\{$this->model_name}Controller'); "; $this->assertEquals($routeWebFileContent, file_get_contents($routeWebPath)); } diff --git a/tests/Generators/Simple/SimpleControllerGeneratorTest.php b/tests/Generators/Simple/SimpleControllerGeneratorTest.php index 9a78def..7719b74 100644 --- a/tests/Generators/Simple/SimpleControllerGeneratorTest.php +++ b/tests/Generators/Simple/SimpleControllerGeneratorTest.php @@ -11,7 +11,7 @@ class SimpleControllerGeneratorTest extends TestCase { $this->artisan('make:crud-simple', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertFileExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php")); + $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); $ctrlClassContent = "full_model_name}; use Illuminate\Http\Request; -class {$this->plural_model_name}Controller extends Controller +class {$this->model_name}Controller extends Controller { /** * Display a listing of the {$this->single_model_var_name}. @@ -107,7 +107,7 @@ class {$this->plural_model_name}Controller extends Controller } } "; - $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/{$this->plural_model_name}Controller.php"))); + $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/{$this->model_name}Controller.php"))); } /** @test */ @@ -115,7 +115,7 @@ class {$this->plural_model_name}Controller extends Controller { $this->artisan('make:crud-simple', ['name' => 'Entities/References/Category', '--no-interaction' => true]); - $this->assertFileExists(app_path("Http/Controllers/CategoriesController.php")); + $this->assertFileExists(app_path("Http/Controllers/CategoryController.php")); $ctrlClassContent = "assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/CategoriesController.php"))); + $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/CategoryController.php"))); } /** @test */ @@ -219,7 +219,7 @@ class CategoriesController extends Controller { $this->artisan('make:crud-simple', ['name' => 'Entities/References/Category', '--parent' => 'Projects', '--no-interaction' => true]); - $this->assertFileExists(app_path("Http/Controllers/Projects/CategoriesController.php")); + $this->assertFileExists(app_path("Http/Controllers/Projects/CategoryController.php")); $ctrlClassContent = "assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/Projects/CategoriesController.php"))); + $this->assertEquals($ctrlClassContent, file_get_contents(app_path("Http/Controllers/Projects/CategoryController.php"))); } }