Browse Source

Fix invalid default value

tags/1.5.0
Nafies Luthfi 5 years ago
parent
commit
04f7bd5460
  1. 4
      src/CrudMake.php
  2. 7
      src/CrudSimpleMake.php
  3. 4
      tests/CrudMakeCommandTest.php
  4. 9
      tests/CrudSimpleMakeCommandTest.php

4
src/CrudMake.php

@ -33,8 +33,8 @@ class CrudMake extends GeneratorCommand
$this->getModelName();
if ($this->modelExists()) {
$confirm = $this->confirm('Model file exists, are you sure to generate CRUD files?', 'no');
if (in_array($confirm, ['yes', 'y']) == false) {
$confirm = $this->confirm('Model file exists, are you sure to generate CRUD files?');
if (!$confirm) {
$this->error("{$this->modelNames['model_name']} model already exists.");
return;
}

7
src/CrudSimpleMake.php

@ -33,8 +33,11 @@ class CrudSimpleMake extends GeneratorCommand
$this->getModelName();
if ($this->modelExists()) {
$this->error("{$this->modelNames['model_name']} model already exists.");
return;
$confirm = $this->confirm('Model file exists, are you sure to generate CRUD files?');
if (!$confirm) {
$this->error("{$this->modelNames['model_name']} model already exists.");
return;
}
}
// Warn if it has no default layout view based on

4
tests/CrudMakeCommandTest.php

@ -41,7 +41,7 @@ class CrudMakeCommandTest extends TestCase
$this->mockConsoleOutput = true;
$this->artisan('make:model', ['name' => $this->model_name, '--no-interaction' => true]);
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true])
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', 'yes');
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', true);
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
@ -71,7 +71,7 @@ class CrudMakeCommandTest extends TestCase
$this->mockConsoleOutput = true;
$this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:crud', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true])
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', 'no')
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', false)
->expectsOutput('Problem model already exists.');
$this->assertFileExists(app_path('Entities/Projects/Problem.php'));

9
tests/CrudSimpleMakeCommandTest.php

@ -39,7 +39,7 @@ class CrudSimpleCommandTest extends TestCase
$this->mockConsoleOutput = true;
$this->artisan('make:model', ['name' => $this->model_name, '--no-interaction' => true]);
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true])
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', 'no')
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', false)
->expectsOutput("{$this->model_name} model already exists.");
$this->assertFileExists(app_path($this->model_name.'.php'));
@ -65,10 +65,11 @@ class CrudSimpleCommandTest extends TestCase
/** @test */
public function it_cannot_generate_crud_files_if_namespaced_model_exists()
{
$this->mockConsoleOutput = true;
$this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:crud-simple', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->assertContains("Problem model already exists.", app(Kernel::class)->output());
$this->artisan('make:crud-simple', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true])
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', false)
->expectsOutput("Problem model already exists.");
$this->assertFileExists(app_path('Entities/Projects/Problem.php'));
$this->assertFileNotExists(app_path("Http/Controllers/ProblemsController.php"));

Loading…
Cancel
Save