Browse Source

Add --formfield command option

tags/1.2.0
Nafies Luthfi 7 years ago
parent
commit
f54ee452dd
  1. 2
      src/CrudMake.php
  2. 2
      src/CrudSimpleMake.php
  3. 69
      tests/CommandOptions/FormfieldOptionsTest.php

2
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.

2
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.

69
tests/CommandOptions/FormfieldOptionsTest.php

@ -0,0 +1,69 @@
<?php
namespace Tests\CommandOptions;
use Tests\TestCase;
use Illuminate\Contracts\Console\Kernel;
class FormfieldOptionsTest extends TestCase
{
/** @test */
public function it_can_generate_views_with_formfield_for_full_crud()
{
$this->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"));
}
}
Loading…
Cancel
Save