From 04f7bd54601ab2251695524ed01562dd9c51d7ca Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 14 Nov 2020 22:50:51 +0800 Subject: [PATCH] Fix invalid default value --- src/CrudMake.php | 4 ++-- src/CrudSimpleMake.php | 7 +++++-- tests/CrudMakeCommandTest.php | 4 ++-- tests/CrudSimpleMakeCommandTest.php | 9 +++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/CrudMake.php b/src/CrudMake.php index 05ac521..6afeafb 100644 --- a/src/CrudMake.php +++ b/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; } diff --git a/src/CrudSimpleMake.php b/src/CrudSimpleMake.php index dd0dcef..3bdf7f1 100644 --- a/src/CrudSimpleMake.php +++ b/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 diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index ca53b52..ebb4ca1 100644 --- a/tests/CrudMakeCommandTest.php +++ b/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')); diff --git a/tests/CrudSimpleMakeCommandTest.php b/tests/CrudSimpleMakeCommandTest.php index 11c155e..9ac980f 100644 --- a/tests/CrudSimpleMakeCommandTest.php +++ b/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"));