Browse Source

Give a warning message if no default_layout_view exists

tags/0.1.2^0 0.1.2
Nafies Luthfi 8 years ago
parent
commit
bef1109473
  1. 27
      src/CrudMake.php
  2. 32
      tests/Generators/ViewsGeneratorTest.php
  3. 8
      tests/TestCase.php

27
src/CrudMake.php

@ -86,7 +86,17 @@ class CrudMake extends Command
{ {
$this->getModelName(); $this->getModelName();
if ( ! $this->modelExists()) {
if ($this->modelExists()) {
$this->error("{$this->modelNames['model_name']} model already exists.");
return;
}
// Warn if it has no default layout view based on
// simple-crud.default_layout_view config
if ($this->defaultLayoutNotExists()) {
$this->warn(config('simple-crud.default_layout_view').' view does not exists.');
}
app(WebRouteGenerator::class, ['command' => $this])->generate(); app(WebRouteGenerator::class, ['command' => $this])->generate();
app(ModelGenerator::class, ['command' => $this])->generate(); app(ModelGenerator::class, ['command' => $this])->generate();
app(MigrationGenerator::class, ['command' => $this])->generate(); app(MigrationGenerator::class, ['command' => $this])->generate();
@ -101,9 +111,6 @@ class CrudMake extends Command
app(ModelPolicyTestGenerator::class, ['command' => $this])->generate(); app(ModelPolicyTestGenerator::class, ['command' => $this])->generate();
$this->info('CRUD files generated successfully!'); $this->info('CRUD files generated successfully!');
} else {
$this->error("{$this->modelNames['model_name']} model already exists.");
}
} }
/** /**
@ -169,4 +176,16 @@ class CrudMake extends Command
app_path($this->modelNames['model_path'].'/'.$this->modelNames['model_name'].'.php') app_path($this->modelNames['model_path'].'/'.$this->modelNames['model_name'].'.php')
); );
} }
/**
* Check for default layout view file existance
*
* @return void
*/
public function defaultLayoutNotExists()
{
return ! $this->files->exists(
resource_path('views/'.str_replace('.', '/', config('simple-crud.default_layout_view')).'.blade.php')
);
}
} }

32
tests/Generators/ViewsGeneratorTest.php

@ -2,6 +2,7 @@
namespace Tests\Generators; namespace Tests\Generators;
use Illuminate\Contracts\Console\Kernel;
use Tests\TestCase; use Tests\TestCase;
class ViewsGeneratorTest extends TestCase class ViewsGeneratorTest extends TestCase
@ -137,4 +138,35 @@ class ViewsGeneratorTest extends TestCase
"; ";
$this->assertEquals($formViewContent, file_get_contents($formViewPath)); $this->assertEquals($formViewContent, file_get_contents($formViewPath));
} }
/** @test */
public function it_not_gives_warning_message_if_default_layout_view_does_exists()
{
$defaultLayoutView = config('simple-crud.default_layout_view');
$this->generateDefaultLayoutView($defaultLayoutView);
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$this->assertNotRegExp("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output());
}
/** @test */
public function it_gives_warning_message_if_default_layout_view_does_not_exists()
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$defaultLayoutView = config('simple-crud.default_layout_view');
$this->assertRegExp("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output());
}
public function generateDefaultLayoutView($defaultLayoutView)
{
$dataViewPathArray = explode('.', $defaultLayoutView);
$fileName = array_pop($dataViewPathArray);
$defaultLayoutPath = resource_path('views/'.implode('/', $dataViewPathArray));
$files = app('Illuminate\Filesystem\Filesystem');
$files->makeDirectory($defaultLayoutPath);
$files->put($defaultLayoutPath.'/'.$fileName.'.blade.php', '');
}
} }

8
tests/TestCase.php

@ -43,6 +43,14 @@ abstract class TestCase extends BaseTestCase
$this->removeFileOrDir(database_path('factories')); $this->removeFileOrDir(database_path('factories'));
$this->removeFileOrDir(resource_path('views/'.$this->table_name)); $this->removeFileOrDir(resource_path('views/'.$this->table_name));
$defaultLayoutsFile = config('simple-crud.default_layout_view');
$dataViewPathArray = explode('.', $defaultLayoutsFile);
$fileName = array_pop($dataViewPathArray);
$defaultLayoutPath = resource_path('views/'.implode('/', $dataViewPathArray));
$this->removeFileOrDir($defaultLayoutPath);
$locale = config('app.locale'); $locale = config('app.locale');
$this->removeFileOrDir(resource_path("lang/{$locale}/app.php")); $this->removeFileOrDir(resource_path("lang/{$locale}/app.php"));
$this->removeFileOrDir(resource_path("lang/{$locale}/{$this->lang_name}.php")); $this->removeFileOrDir(resource_path("lang/{$locale}/{$this->lang_name}.php"));

Loading…
Cancel
Save