From e3d0ae0b19f089a1ebe93c7c99e1cfaccdc96e4f Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 15 Oct 2017 12:10:20 +0800 Subject: [PATCH] Support for two-words model name --- src/CrudMake.php | 2 +- src/stubs/controller.model.stub | 24 ++++++++++++------------ src/stubs/test-feature.stub | 26 +++++++++++++------------- src/stubs/test-unit.stub | 4 ++-- src/stubs/view-index.stub | 20 ++++++++++---------- tests/CrudMakeCommandTest.php | 6 +++--- tests/Generators/ControllerGeneratorTest.php | 6 +++--- tests/Generators/FeatureTestGeneratorTest.php | 14 +++++++------- tests/Generators/ViewsGeneratorTest.php | 6 +++--- tests/TestCase.php | 4 ++-- 10 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/CrudMake.php b/src/CrudMake.php index 3931ee9..35265e1 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -27,7 +27,7 @@ class CrudMake extends Command * * @var array */ - public $stubModelNames = ['Masters', 'Master', 'masters', 'master']; + public $stubModelNames = ['Masters', 'Master', 'masters', 'master', 'mstrCollections', 'singleMstr']; /** * Construct CrudMake class diff --git a/src/stubs/controller.model.stub b/src/stubs/controller.model.stub index f0e2d22..35a0881 100644 --- a/src/stubs/controller.model.stub +++ b/src/stubs/controller.model.stub @@ -8,14 +8,14 @@ use Illuminate\Http\Request; class MastersController extends Controller { /** - * Display a listing of the master. + * Display a listing of the singleMstr. * * @return \Illuminate\Http\Response */ public function index() { $editableMaster = null; - $masters = Master::where(function ($query) { + $mstrCollections = Master::where(function ($query) { $query->where('name', 'like', '%'.request('q').'%'); })->paginate(25); @@ -23,11 +23,11 @@ class MastersController extends Controller $editableMaster = Master::find(request('id')); } - return view('masters.index', compact('masters', 'editableMaster')); + return view('masters.index', compact('mstrCollections', 'editableMaster')); } /** - * Store a newly created master in storage. + * Store a newly created singleMstr in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response @@ -45,13 +45,13 @@ class MastersController extends Controller } /** - * Update the specified master in storage. + * Update the specified singleMstr in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Master $master + * @param \App\Master $singleMstr * @return \Illuminate\Http\Response */ - public function update(Request $request, Master $master) + public function update(Request $request, Master $singleMstr) { $this->validate($request, [ 'name' => 'required|max:60', @@ -60,18 +60,18 @@ class MastersController extends Controller $routeParam = request()->only('page', 'q'); - $master = $master->update($request->only('name', 'description')); + $singleMstr = $singleMstr->update($request->only('name', 'description')); return redirect()->route('masters.index', $routeParam); } /** - * Remove the specified master from storage. + * Remove the specified singleMstr from storage. * - * @param \App\Master $master + * @param \App\Master $singleMstr * @return \Illuminate\Http\Response */ - public function destroy(Master $master) + public function destroy(Master $singleMstr) { $this->validate(request(), [ 'master_id' => 'required', @@ -79,7 +79,7 @@ class MastersController extends Controller $routeParam = request()->only('page', 'q'); - if (request('master_id') == $master->id && $master->delete()) { + if (request('master_id') == $singleMstr->id && $singleMstr->delete()) { return redirect()->route('masters.index', $routeParam); } diff --git a/src/stubs/test-feature.stub b/src/stubs/test-feature.stub index 795ffed..f1441d4 100644 --- a/src/stubs/test-feature.stub +++ b/src/stubs/test-feature.stub @@ -13,13 +13,13 @@ class ManageMastersTest extends TestCase /** @test */ public function user_can_see_master_list_in_master_index_page() { - $master1 = factory(Master::class)->create(['name' => 'Testing name', 'description' => 'Testing 123']); - $master2 = factory(Master::class)->create(['name' => 'Testing name', 'description' => 'Testing 456']); + $singleMstr1 = factory(Master::class)->create(['name' => 'Testing name', 'description' => 'Testing 123']); + $singleMstr2 = factory(Master::class)->create(['name' => 'Testing name', 'description' => 'Testing 456']); $this->loginAsUser(); $this->visit(route('masters.index')); - $this->see($master1->name); - $this->see($master2->name); + $this->see($singleMstr1->name); + $this->see($singleMstr2->name); } /** @test */ @@ -47,11 +47,11 @@ class ManageMastersTest extends TestCase public function user_can_edit_a_master_within_search_query() { $this->loginAsUser(); - $master = factory(Master::class)->create(['name' => 'Testing 123']); + $singleMstr = factory(Master::class)->create(['name' => 'Testing 123']); $this->visit(route('masters.index', ['q' => '123'])); - $this->click('edit-master-'.$master->id); - $this->seePageIs(route('masters.index', ['action' => 'edit', 'id' => $master->id, 'q' => '123'])); + $this->click('edit-singleMstr-'.$singleMstr->id); + $this->seePageIs(route('masters.index', ['action' => 'edit', 'id' => $singleMstr->id, 'q' => '123'])); $this->type('Master 1 name', 'name'); $this->type('Master 1 description', 'description'); @@ -69,20 +69,20 @@ class ManageMastersTest extends TestCase public function user_can_delete_a_master() { $this->loginAsUser(); - $master = factory(Master::class)->create(); + $singleMstr = factory(Master::class)->create(); - $this->visit(route('masters.index', [$master->id])); - $this->click('del-master-'.$master->id); - $this->seePageIs(route('masters.index', ['action' => 'delete', 'id' => $master->id])); + $this->visit(route('masters.index', [$singleMstr->id])); + $this->click('del-singleMstr-'.$singleMstr->id); + $this->seePageIs(route('masters.index', ['action' => 'delete', 'id' => $singleMstr->id])); $this->seeInDatabase('masters', [ - 'id' => $master->id, + 'id' => $singleMstr->id, ]); $this->press(trans('app.delete_confirm_button')); $this->dontSeeInDatabase('masters', [ - 'id' => $master->id, + 'id' => $singleMstr->id, ]); } } diff --git a/src/stubs/test-unit.stub b/src/stubs/test-unit.stub index e9b0834..60123cf 100644 --- a/src/stubs/test-unit.stub +++ b/src/stubs/test-unit.stub @@ -13,7 +13,7 @@ class MasterTest extends TestCase /** @test */ public function it_has_name_attribute() { - $master = factory(Master::class)->create(['name' => 'Master 1 name']); - $this->assertEquals('Master 1 name', $master->name); + $singleMstr = factory(Master::class)->create(['name' => 'Master 1 name']); + $this->assertEquals('Master 1 name', $singleMstr->name); } } diff --git a/src/stubs/view-index.stub b/src/stubs/view-index.stub index 3755bd7..147264f 100644 --- a/src/stubs/view-index.stub +++ b/src/stubs/view-index.stub @@ -8,7 +8,7 @@
@@ -30,30 +30,30 @@ - @foreach($masters as $key => $master) + @foreach($mstrCollections as $key => $singleMstr) - {{ $masters->firstItem() + $key }} - {{ $master->name }} - {{ $master->description }} + {{ $mstrCollections->firstItem() + $key }} + {{ $singleMstr->name }} + {{ $singleMstr->description }} {!! link_to_route( 'masters.index', trans('app.edit'), - ['action' => 'edit', 'id' => $master->id] + Request::only('page', 'q'), - ['id' => 'edit-master-' . $master->id] + ['action' => 'edit', 'id' => $singleMstr->id] + Request::only('page', 'q'), + ['id' => 'edit-singleMstr-' . $singleMstr->id] ) !!} | {!! link_to_route( 'masters.index', trans('app.delete'), - ['action' => 'delete', 'id' => $master->id] + Request::only('page', 'q'), - ['id' => 'del-master-' . $master->id] + ['action' => 'delete', 'id' => $singleMstr->id] + Request::only('page', 'q'), + ['id' => 'del-singleMstr-' . $singleMstr->id] ) !!} @endforeach -
{{ $masters->appends(Request::except('page'))->render() }}
+
{{ $mstrCollections->appends(Request::except('page'))->render() }}
diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index 7ab6906..7cd5157 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -13,7 +13,7 @@ class CrudMakeCommandTest extends TestCase $crudMaker = app(CrudMake::class); $this->assertEquals([ - 'Masters', 'Master', 'masters', 'master', + 'Masters', 'Master', 'masters', 'master', 'mstrCollections', 'singleMstr', ], $crudMaker->stubModelNames); } @@ -45,7 +45,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php")); $this->assertFileExists(resource_path("views/{$this->table_name}/forms.blade.php")); - $this->assertFileExists(resource_path("lang/en/{$this->single_model_var_name}.php")); + $this->assertFileExists(resource_path("lang/en/{$this->lang_name}.php")); $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php")); $this->assertFileExists(base_path("routes/web.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$this->plural_model_name}Test.php")); @@ -68,7 +68,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php")); $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php")); - $this->assertFileNotExists(resource_path("lang/en/{$this->single_model_var_name}.php")); + $this->assertFileNotExists(resource_path("lang/en/{$this->lang_name}.php")); $this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php")); $this->assertFileNotExists(base_path("routes/web.php")); $this->assertFileNotExists(base_path("tests/Feature/Manage{$this->plural_model_name}Test.php")); diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php index 23c480a..7b68ea3 100644 --- a/tests/Generators/ControllerGeneratorTest.php +++ b/tests/Generators/ControllerGeneratorTest.php @@ -37,7 +37,7 @@ class {$this->plural_model_name}Controller extends Controller \$editable{$this->model_name} = {$this->model_name}::find(request('id')); } - return view('{$this->table_name}.index', compact('{$this->table_name}', 'editable{$this->model_name}')); + return view('{$this->table_name}.index', compact('{$this->collection_model_var_name}', 'editable{$this->model_name}')); } /** @@ -88,12 +88,12 @@ class {$this->plural_model_name}Controller extends Controller public function destroy({$this->model_name} \${$this->single_model_var_name}) { \$this->validate(request(), [ - '{$this->single_model_var_name}_id' => 'required', + '{$this->lang_name}_id' => 'required', ]); \$routeParam = request()->only('page', 'q'); - if (request('{$this->single_model_var_name}_id') == \${$this->single_model_var_name}->id && \${$this->single_model_var_name}->delete()) { + if (request('{$this->lang_name}_id') == \${$this->single_model_var_name}->id && \${$this->single_model_var_name}->delete()) { return redirect()->route('{$this->table_name}.index', \$routeParam); } diff --git a/tests/Generators/FeatureTestGeneratorTest.php b/tests/Generators/FeatureTestGeneratorTest.php index bbb6b26..82f1d7f 100644 --- a/tests/Generators/FeatureTestGeneratorTest.php +++ b/tests/Generators/FeatureTestGeneratorTest.php @@ -62,7 +62,7 @@ class Manage{$this->plural_model_name}Test extends TestCase use DatabaseMigrations; /** @test */ - public function user_can_see_{$this->single_model_var_name}_list_in_{$this->single_model_var_name}_index_page() + public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { \${$this->single_model_var_name}1 = factory({$this->model_name}::class)->create(['name' => 'Testing name', 'description' => 'Testing 123']); \${$this->single_model_var_name}2 = factory({$this->model_name}::class)->create(['name' => 'Testing name', 'description' => 'Testing 456']); @@ -74,17 +74,17 @@ class Manage{$this->plural_model_name}Test extends TestCase } /** @test */ - public function user_can_create_a_{$this->single_model_var_name}() + public function user_can_create_a_{$this->lang_name}() { \$this->loginAsUser(); \$this->visit(route('{$this->table_name}.index')); - \$this->click(trans('{$this->single_model_var_name}.create')); + \$this->click(trans('{$this->lang_name}.create')); \$this->seePageIs(route('{$this->table_name}.index', ['action' => 'create'])); \$this->type('{$this->model_name} 1 name', 'name'); \$this->type('{$this->model_name} 1 description', 'description'); - \$this->press(trans('{$this->single_model_var_name}.create')); + \$this->press(trans('{$this->lang_name}.create')); \$this->seePageIs(route('{$this->table_name}.index')); @@ -95,7 +95,7 @@ class Manage{$this->plural_model_name}Test extends TestCase } /** @test */ - public function user_can_edit_a_{$this->single_model_var_name}_within_search_query() + public function user_can_edit_a_{$this->lang_name}_within_search_query() { \$this->loginAsUser(); \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); @@ -106,7 +106,7 @@ class Manage{$this->plural_model_name}Test extends TestCase \$this->type('{$this->model_name} 1 name', 'name'); \$this->type('{$this->model_name} 1 description', 'description'); - \$this->press(trans('{$this->single_model_var_name}.update')); + \$this->press(trans('{$this->lang_name}.update')); \$this->seePageIs(route('{$this->table_name}.index', ['q' => '123'])); @@ -117,7 +117,7 @@ class Manage{$this->plural_model_name}Test extends TestCase } /** @test */ - public function user_can_delete_a_{$this->single_model_var_name}() + public function user_can_delete_a_{$this->lang_name}() { \$this->loginAsUser(); \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php index 5e8623a..cba447b 100644 --- a/tests/Generators/ViewsGeneratorTest.php +++ b/tests/Generators/ViewsGeneratorTest.php @@ -23,7 +23,7 @@ class ViewsGeneratorTest extends TestCase

{{ trans('{$this->lang_name}.list') }} - {{ trans('app.total') }} : {{ \${$this->collection_model_var_name}->total() }} {{ trans('{$this->lang_name}.{$this->single_model_var_name}') }} + {{ trans('app.total') }} : {{ \${$this->collection_model_var_name}->total() }} {{ trans('{$this->lang_name}.{$this->lang_name}') }}

@@ -115,7 +115,7 @@ class ViewsGeneratorTest extends TestCase

{{ \$editable{$this->model_name}->name }}

- {!! \$errors->first('{$this->single_model_var_name}_id', ':message') !!} + {!! \$errors->first('{$this->lang_name}_id', ':message') !!}

{{ trans('app.delete_confirm') }}
@@ -125,7 +125,7 @@ class ViewsGeneratorTest extends TestCase trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], [ - '{$this->single_model_var_name}_id' => \$editable{$this->model_name}->id, + '{$this->lang_name}_id' => \$editable{$this->model_name}->id, 'page' => request('page'), 'q' => request('q'), ] diff --git a/tests/TestCase.php b/tests/TestCase.php index e04ead1..0642dfa 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,7 +16,7 @@ abstract class TestCase extends BaseTestCase public function setUp() { parent::setUp(); - $this->model_name = 'Category'; + $this->model_name = 'PaymentMethod'; $this->plural_model_name = str_plural($this->model_name); $this->table_name = snake_case($this->plural_model_name); @@ -39,7 +39,7 @@ abstract class TestCase extends BaseTestCase $this->removeFileOrDir(database_path('migrations')); $this->removeFileOrDir(database_path('factories')); $this->removeFileOrDir(resource_path('views/'.$this->table_name)); - $this->removeFileOrDir(resource_path("lang/en/{$this->single_model_var_name}.php")); + $this->removeFileOrDir(resource_path("lang/en/{$this->lang_name}.php")); $this->removeFileOrDir(base_path('routes')); $this->removeFileOrDir(base_path('tests/BrowserKitTest.php')); $this->removeFileOrDir(base_path('tests/Feature'));