diff --git a/src/CrudMake.php b/src/CrudMake.php index 9424c0f..f0ebb6d 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -27,7 +27,7 @@ class CrudMake extends Command * * @var array */ - private $stubModelNames = ['Master', 'Masters', 'master', 'masters']; + private $stubModelNames = ['Masters', 'Master', 'masters', 'master']; /** * Construct CrudMake class @@ -85,10 +85,10 @@ class CrudMake extends Command $modelName = $this->argument('name'); $this->modelNames = [ - 'model_name' => $modelName, 'plural_model_name' => str_plural($modelName), - 'lowercase_single_model_name' => strtolower($modelName), + 'model_name' => $modelName, 'lowercase_plural_model_name' => strtolower(str_plural($modelName)), + 'lowercase_single_model_name' => strtolower($modelName), ]; } diff --git a/src/stubs/test-feature.stub b/src/stubs/test-feature.stub index fbe1eaf..795ffed 100644 --- a/src/stubs/test-feature.stub +++ b/src/stubs/test-feature.stub @@ -4,8 +4,6 @@ namespace Tests\Feature; use App\Master; use Tests\BrowserKitTest as TestCase; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use Illuminate\Foundation\Testing\DatabaseMigrations; class ManageMastersTest extends TestCase diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php index 617e83e..9350a90 100644 --- a/tests/Generators/ControllerGeneratorTest.php +++ b/tests/Generators/ControllerGeneratorTest.php @@ -16,32 +16,32 @@ class ControllerGeneratorTest extends TestCase namespace App\Http\Controllers; -use App\Item; +use App\\{$this->modelName}; use Illuminate\Http\Request; -class ItemsController extends Controller +class {$this->pluralModelName}Controller extends Controller { /** - * Display a listing of the item. + * Display a listing of the {$this->singleModelName}. * * @return \Illuminate\Http\Response */ public function index() { - \$editableItem = null; - \$items = Item::where(function (\$query) { + \$editable{$this->modelName} = null; + \${$this->tableName} = {$this->modelName}::where(function (\$query) { \$query->where('name', 'like', '%'.request('q').'%'); })->paginate(25); if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { - \$editableItem = Item::find(request('id')); + \$editable{$this->modelName} = {$this->modelName}::find(request('id')); } - return view('items.index', compact('items', 'editableItem')); + return view('{$this->tableName}.index', compact('{$this->tableName}', 'editable{$this->modelName}')); } /** - * Store a newly created item in storage. + * Store a newly created {$this->singleModelName} in storage. * * @param \Illuminate\Http\Request \$request * @return \Illuminate\Http\Response @@ -53,19 +53,19 @@ class ItemsController extends Controller 'description' => 'nullable|max:255', ]); - Item::create(\$request->only('name', 'description')); + {$this->modelName}::create(\$request->only('name', 'description')); - return redirect()->route('items.index'); + return redirect()->route('{$this->tableName}.index'); } /** - * Update the specified item in storage. + * Update the specified {$this->singleModelName} in storage. * * @param \Illuminate\Http\Request \$request - * @param \App\Item \$item + * @param \App\\{$this->modelName} \${$this->singleModelName} * @return \Illuminate\Http\Response */ - public function update(Request \$request, Item \$item) + public function update(Request \$request, {$this->modelName} \${$this->singleModelName}) { \$this->validate(\$request, [ 'name' => 'required|max:60', @@ -74,27 +74,27 @@ class ItemsController extends Controller \$routeParam = request()->only('page', 'q'); - \$item = \$item->update(\$request->only('name', 'description')); + \${$this->singleModelName} = \${$this->singleModelName}->update(\$request->only('name', 'description')); - return redirect()->route('items.index', \$routeParam); + return redirect()->route('{$this->tableName}.index', \$routeParam); } /** - * Remove the specified item from storage. + * Remove the specified {$this->singleModelName} from storage. * - * @param \App\Item \$item + * @param \App\\{$this->modelName} \${$this->singleModelName} * @return \Illuminate\Http\Response */ - public function destroy(Item \$item) + public function destroy({$this->modelName} \${$this->singleModelName}) { \$this->validate(request(), [ - 'item_id' => 'required', + '{$this->singleModelName}_id' => 'required', ]); \$routeParam = request()->only('page', 'q'); - if (request('item_id') == \$item->id && \$item->delete()) { - return redirect()->route('items.index', \$routeParam); + if (request('{$this->singleModelName}_id') == \${$this->singleModelName}->id && \${$this->singleModelName}->delete()) { + return redirect()->route('{$this->tableName}.index', \$routeParam); } return back(); diff --git a/tests/Generators/FeatureTestGeneratorTest.php b/tests/Generators/FeatureTestGeneratorTest.php index 0dfd598..c05b7e2 100644 --- a/tests/Generators/FeatureTestGeneratorTest.php +++ b/tests/Generators/FeatureTestGeneratorTest.php @@ -53,89 +53,87 @@ abstract class BrowserKitTest extends BaseTestCase namespace Tests\Feature; -use App\Item; +use App\\{$this->modelName}; use Tests\BrowserKitTest as TestCase; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use Illuminate\Foundation\Testing\DatabaseMigrations; -class ManageItemsTest extends TestCase +class Manage{$this->pluralModelName}Test extends TestCase { use DatabaseMigrations; /** @test */ - public function user_can_see_item_list_in_item_index_page() + public function user_can_see_{$this->singleModelName}_list_in_{$this->singleModelName}_index_page() { - \$item1 = factory(Item::class)->create(['name' => 'Testing name', 'description' => 'Testing 123']); - \$item2 = factory(Item::class)->create(['name' => 'Testing name', 'description' => 'Testing 456']); + \${$this->singleModelName}1 = factory({$this->modelName}::class)->create(['name' => 'Testing name', 'description' => 'Testing 123']); + \${$this->singleModelName}2 = factory({$this->modelName}::class)->create(['name' => 'Testing name', 'description' => 'Testing 456']); \$this->loginAsUser(); - \$this->visit(route('items.index')); - \$this->see(\$item1->name); - \$this->see(\$item2->name); + \$this->visit(route('{$this->tableName}.index')); + \$this->see(\${$this->singleModelName}1->name); + \$this->see(\${$this->singleModelName}2->name); } /** @test */ - public function user_can_create_a_item() + public function user_can_create_a_{$this->singleModelName}() { \$this->loginAsUser(); - \$this->visit(route('items.index')); + \$this->visit(route('{$this->tableName}.index')); - \$this->click(trans('item.create')); - \$this->seePageIs(route('items.index', ['action' => 'create'])); + \$this->click(trans('{$this->singleModelName}.create')); + \$this->seePageIs(route('{$this->tableName}.index', ['action' => 'create'])); - \$this->type('Item 1 name', 'name'); - \$this->type('Item 1 description', 'description'); - \$this->press(trans('item.create')); + \$this->type('{$this->modelName} 1 name', 'name'); + \$this->type('{$this->modelName} 1 description', 'description'); + \$this->press(trans('{$this->singleModelName}.create')); - \$this->seePageIs(route('items.index')); + \$this->seePageIs(route('{$this->tableName}.index')); - \$this->seeInDatabase('items', [ - 'name' => 'Item 1 name', - 'description' => 'Item 1 description', + \$this->seeInDatabase('{$this->tableName}', [ + 'name' => '{$this->modelName} 1 name', + 'description' => '{$this->modelName} 1 description', ]); } /** @test */ - public function user_can_edit_a_item_within_search_query() + public function user_can_edit_a_{$this->singleModelName}_within_search_query() { \$this->loginAsUser(); - \$item = factory(Item::class)->create(['name' => 'Testing 123']); + \${$this->singleModelName} = factory({$this->modelName}::class)->create(['name' => 'Testing 123']); - \$this->visit(route('items.index', ['q' => '123'])); - \$this->click('edit-item-'.\$item->id); - \$this->seePageIs(route('items.index', ['action' => 'edit', 'id' => \$item->id, 'q' => '123'])); + \$this->visit(route('{$this->tableName}.index', ['q' => '123'])); + \$this->click('edit-{$this->singleModelName}-'.\${$this->singleModelName}->id); + \$this->seePageIs(route('{$this->tableName}.index', ['action' => 'edit', 'id' => \${$this->singleModelName}->id, 'q' => '123'])); - \$this->type('Item 1 name', 'name'); - \$this->type('Item 1 description', 'description'); - \$this->press(trans('item.update')); + \$this->type('{$this->modelName} 1 name', 'name'); + \$this->type('{$this->modelName} 1 description', 'description'); + \$this->press(trans('{$this->singleModelName}.update')); - \$this->seePageIs(route('items.index', ['q' => '123'])); + \$this->seePageIs(route('{$this->tableName}.index', ['q' => '123'])); - \$this->seeInDatabase('items', [ - 'name' => 'Item 1 name', - 'description' => 'Item 1 description', + \$this->seeInDatabase('{$this->tableName}', [ + 'name' => '{$this->modelName} 1 name', + 'description' => '{$this->modelName} 1 description', ]); } /** @test */ - public function user_can_delete_a_item() + public function user_can_delete_a_{$this->singleModelName}() { \$this->loginAsUser(); - \$item = factory(Item::class)->create(); + \${$this->singleModelName} = factory({$this->modelName}::class)->create(); - \$this->visit(route('items.index', [\$item->id])); - \$this->click('del-item-'.\$item->id); - \$this->seePageIs(route('items.index', ['action' => 'delete', 'id' => \$item->id])); + \$this->visit(route('{$this->tableName}.index', [\${$this->singleModelName}->id])); + \$this->click('del-{$this->singleModelName}-'.\${$this->singleModelName}->id); + \$this->seePageIs(route('{$this->tableName}.index', ['action' => 'delete', 'id' => \${$this->singleModelName}->id])); - \$this->seeInDatabase('items', [ - 'id' => \$item->id, + \$this->seeInDatabase('{$this->tableName}', [ + 'id' => \${$this->singleModelName}->id, ]); \$this->press(trans('app.delete_confirm_button')); - \$this->dontSeeInDatabase('items', [ - 'id' => \$item->id, + \$this->dontSeeInDatabase('{$this->tableName}', [ + 'id' => \${$this->singleModelName}->id, ]); } } diff --git a/tests/Generators/LangGeneratorTest.php b/tests/Generators/LangGeneratorTest.php index 506fbab..31b11dc 100644 --- a/tests/Generators/LangGeneratorTest.php +++ b/tests/Generators/LangGeneratorTest.php @@ -17,28 +17,28 @@ class LangGeneratorTest extends TestCase return [ // Labels - 'item' => 'Item', - 'list' => 'Item List', - 'search' => 'Search Item', - 'not_found' => 'Item not found.', - 'empty' => 'Item is empty.', - 'back_to_show' => 'Back to Item Detail', - 'back_to_index' => 'Back to Item List', + '{$this->singleModelName}' => '{$this->modelName}', + 'list' => '{$this->modelName} List', + 'search' => 'Search {$this->modelName}', + 'not_found' => '{$this->modelName} not found.', + 'empty' => '{$this->modelName} is empty.', + 'back_to_show' => 'Back to {$this->modelName} Detail', + 'back_to_index' => 'Back to {$this->modelName} List', // Actions - 'create' => 'Create new Item', - 'created' => 'Create new Item succeded.', - 'edit' => 'Edit Item', - 'update' => 'Update Item', - 'updated' => 'Update Item succeded.', - 'delete' => 'Delete Item', - 'delete_confirm' => 'Are you sure to delete this Item?', - 'deleted' => 'Delete Item succeded.', - 'undeleted' => 'Item not deleted.', + 'create' => 'Create new {$this->modelName}', + 'created' => 'Create new {$this->modelName} succeded.', + 'edit' => 'Edit {$this->modelName}', + 'update' => 'Update {$this->modelName}', + 'updated' => 'Update {$this->modelName} succeded.', + 'delete' => 'Delete {$this->modelName}', + 'delete_confirm' => 'Are you sure to delete this {$this->modelName}?', + 'deleted' => 'Delete {$this->modelName} succeded.', + 'undeleted' => '{$this->modelName} not deleted.', // Attributes - 'name' => 'Item Name', - 'description' => 'Item Description', + 'name' => '{$this->modelName} Name', + 'description' => '{$this->modelName} Description', ]; "; $this->assertEquals($langFileContent, file_get_contents($langPath)); diff --git a/tests/Generators/MigrationGeneratorTest.php b/tests/Generators/MigrationGeneratorTest.php index 9c84e9b..1afebdb 100644 --- a/tests/Generators/MigrationGeneratorTest.php +++ b/tests/Generators/MigrationGeneratorTest.php @@ -19,7 +19,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateItemsTable extends Migration +class Create{$this->pluralModelName}Table extends Migration { /** * Run the migrations. @@ -28,7 +28,7 @@ class CreateItemsTable extends Migration */ public function up() { - Schema::create('items', function (Blueprint \$table) { + Schema::create('{$this->tableName}', function (Blueprint \$table) { \$table->increments('id'); \$table->string('name', 60); \$table->string('description')->nullable(); @@ -43,7 +43,7 @@ class CreateItemsTable extends Migration */ public function down() { - Schema::dropIfExists('items'); + Schema::dropIfExists('{$this->tableName}'); } } "; diff --git a/tests/Generators/ModelFactoryGeneratorTest.php b/tests/Generators/ModelFactoryGeneratorTest.php index 7263bac..cce5e85 100644 --- a/tests/Generators/ModelFactoryGeneratorTest.php +++ b/tests/Generators/ModelFactoryGeneratorTest.php @@ -15,10 +15,10 @@ class ModelFactoryGeneratorTest extends TestCase $this->assertFileExists($modelFactoryPath); $modelFactoryContent = "modelName}; use Faker\Generator as Faker; -\$factory->define(Item::class, function (Faker \$faker) { +\$factory->define({$this->modelName}::class, function (Faker \$faker) { return [ 'name' => \$faker->word, diff --git a/tests/Generators/ModelGeneratorTest.php b/tests/Generators/ModelGeneratorTest.php index 3a9055e..7fb9591 100644 --- a/tests/Generators/ModelGeneratorTest.php +++ b/tests/Generators/ModelGeneratorTest.php @@ -19,7 +19,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; -class Item extends Model +class {$this->modelName} extends Model { protected \$fillable = ['name', 'description']; } diff --git a/tests/Generators/ModelTestGeneratorTest.php b/tests/Generators/ModelTestGeneratorTest.php index 91476d4..a42abd0 100644 --- a/tests/Generators/ModelTestGeneratorTest.php +++ b/tests/Generators/ModelTestGeneratorTest.php @@ -16,19 +16,19 @@ class ModelTestGeneratorTest extends TestCase namespace Tests\Unit\Models; -use App\Item; +use App\\{$this->modelName}; use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\TestCase; -class ItemTest extends TestCase +class {$this->modelName}Test extends TestCase { use DatabaseMigrations; /** @test */ public function it_has_name_attribute() { - \$item = factory(Item::class)->create(['name' => 'Item 1 name']); - \$this->assertEquals('Item 1 name', \$item->name); + \${$this->singleModelName} = factory({$this->modelName}::class)->create(['name' => '{$this->modelName} 1 name']); + \$this->assertEquals('{$this->modelName} 1 name', \${$this->singleModelName}->name); } } "; diff --git a/tests/Generators/RouteWebGeneratorTest.php b/tests/Generators/RouteWebGeneratorTest.php index 909b350..deef0e6 100644 --- a/tests/Generators/RouteWebGeneratorTest.php +++ b/tests/Generators/RouteWebGeneratorTest.php @@ -15,7 +15,7 @@ class RouteWebGeneratorTest extends TestCase $this->assertFileExists($routeWebPath); $routeWebFileContent = "tableName}', '{$this->pluralModelName}Controller'); "; $this->assertEquals($routeWebFileContent, file_get_contents($routeWebPath)); } diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php index 92f1dd2..3ba83ca 100644 --- a/tests/Generators/ViewsGeneratorTest.php +++ b/tests/Generators/ViewsGeneratorTest.php @@ -15,64 +15,64 @@ class ViewsGeneratorTest extends TestCase $this->assertFileExists($indexViewPath); $indexViewContent = "@extends('layouts.app') -@section('title', trans('item.list')) +@section('title', trans('{$this->singleModelName}.list')) @section('content')
| {{ trans('app.table_no') }} | -{{ trans('item.name') }} | -{{ trans('item.description') }} | +{{ trans('{$this->singleModelName}.name') }} | +{{ trans('{$this->singleModelName}.description') }} | {{ trans('app.action') }} | |
|---|---|---|---|---|---|---|
| {{ \$items->firstItem() + \$key }} | -{{ \$item->name }} | -{{ \$item->description }} | +{{ \${$this->tableName}->firstItem() + \$key }} | +{{ \${$this->singleModelName}->name }} | +{{ \${$this->singleModelName}->description }} | {!! link_to_route( - 'items.index', + '{$this->tableName}.index', trans('app.edit'), - ['action' => 'edit', 'id' => \$item->id] + Request::only('page', 'q'), - ['id' => 'edit-item-' . \$item->id] + ['action' => 'edit', 'id' => \${$this->singleModelName}->id] + Request::only('page', 'q'), + ['id' => 'edit-{$this->singleModelName}-' . \${$this->singleModelName}->id] ) !!} | {!! link_to_route( - 'items.index', + '{$this->tableName}.index', trans('app.delete'), - ['action' => 'delete', 'id' => \$item->id] + Request::only('page', 'q'), - ['id' => 'del-item-' . \$item->id] + ['action' => 'delete', 'id' => \${$this->singleModelName}->id] + Request::only('page', 'q'), + ['id' => 'del-{$this->singleModelName}-' . \${$this->singleModelName}->id] ) !!} |
{{ \$editableItem->name }}
- {!! \$errors->first('item_id', ':message') !!} + +{{ \$editable{$this->modelName}->name }}
+ {!! \$errors->first('{$this->singleModelName}_id', ':message') !!}