diff --git a/src/CrudMake.php b/src/CrudMake.php index 8d0f704..88cc1b9 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -9,7 +9,7 @@ class CrudMake extends GeneratorCommand * * @var string */ - protected $signature = 'make:crud {name} {--p|parent=} {--t|tests-only}'; + protected $signature = 'make:crud {name} {--p|parent=} {--t|tests-only} {--f|formfield}'; /** * The console command description. diff --git a/src/CrudSimpleMake.php b/src/CrudSimpleMake.php index 3521dfc..fb7ab92 100644 --- a/src/CrudSimpleMake.php +++ b/src/CrudSimpleMake.php @@ -9,7 +9,7 @@ class CrudSimpleMake extends GeneratorCommand * * @var string */ - protected $signature = 'make:crud-simple {name} {--p|parent=} {--t|tests-only}'; + protected $signature = 'make:crud-simple {name} {--p|parent=} {--t|tests-only} {--f|formfield}'; /** * The console command description. diff --git a/tests/CommandOptions/FormfieldOptionsTest.php b/tests/CommandOptions/FormfieldOptionsTest.php new file mode 100644 index 0000000..87a4c49 --- /dev/null +++ b/tests/CommandOptions/FormfieldOptionsTest.php @@ -0,0 +1,69 @@ +artisan('make:crud', [ + 'name' => $this->model_name, + '--formfield' => true, + ]); + + $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->model_name}Controller.php")); + + $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); + $this->assertFileExists($migrationFilePath); + + $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php")); + $this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php")); + $this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php")); + $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php")); + + $localeConfig = config('app.locale'); + $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + + $this->assertFileExists(base_path("routes/web.php")); + $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php")); + $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php")); + $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); + } + + /** @test */ + public function it_can_generate_views_with_formfield_for_simple_crud() + { + $this->artisan('make:crud-simple', [ + 'name' => $this->model_name, + '--formfield' => true, + ]); + + $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->model_name}Controller.php")); + + $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); + $this->assertFileExists($migrationFilePath); + + $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php")); + $this->assertFileExists(resource_path("views/{$this->table_name}/forms.blade.php")); + + $localeConfig = config('app.locale'); + $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + + $this->assertFileExists(base_path("routes/web.php")); + $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php")); + $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php")); + $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); + } +}