From 537478e2d311f1dd150cda490cee5bbcd11f3bb4 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 9 Jan 2021 23:12:32 +0800 Subject: [PATCH] Fix some deprecated assertions --- src/GeneratorCommand.php | 2 +- tests/CommandOptions/FullCrudBs3OptionsTest.php | 4 +- .../FullCrudFormRequestOptionsTest.php | 4 +- .../FullCrudFormfieldBs3OptionsTest.php | 4 +- .../FullCrudFormfieldOptionsTest.php | 8 +-- tests/CommandOptions/SimpleCrudBs3OptionsTest.php | 2 +- .../SimpleCrudFormfieldBs3OptionsTest.php | 2 +- .../SimpleCrudFormfieldOptionsTest.php | 2 +- tests/CommandOptions/TestsOnlyOptionsTest.php | 22 ++++----- tests/CrudApiMakeCommandTest.php | 57 +++++++++++----------- tests/CrudMakeCommandTest.php | 44 ++++++++--------- tests/CrudSimpleMakeCommandTest.php | 52 ++++++++++---------- tests/Generators/ModelGeneratorTest.php | 10 +++- tests/Generators/Simple/ViewsGeneratorTest.php | 4 +- tests/Generators/ViewsGeneratorTest.php | 4 +- 15 files changed, 114 insertions(+), 107 deletions(-) diff --git a/src/GeneratorCommand.php b/src/GeneratorCommand.php index b8dced3..8b9cb67 100644 --- a/src/GeneratorCommand.php +++ b/src/GeneratorCommand.php @@ -88,7 +88,7 @@ class GeneratorCommand extends Command $inputName = explode('/', ucfirst($modelName)); array_pop($inputName); - return implode('/', $inputName); + return implode('/', $inputName) ?: 'Models'; } /** diff --git a/tests/CommandOptions/FullCrudBs3OptionsTest.php b/tests/CommandOptions/FullCrudBs3OptionsTest.php index 823f3eb..5b52aa4 100644 --- a/tests/CommandOptions/FullCrudBs3OptionsTest.php +++ b/tests/CommandOptions/FullCrudBs3OptionsTest.php @@ -12,7 +12,7 @@ class FullCrudBs3OptionsTest extends TestCase { $this->artisan('make:crud', ['name' => $this->model_name, '--bs3' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); @@ -23,7 +23,7 @@ class FullCrudBs3OptionsTest extends TestCase $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")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); diff --git a/tests/CommandOptions/FullCrudFormRequestOptionsTest.php b/tests/CommandOptions/FullCrudFormRequestOptionsTest.php index 4cac918..fe303fe 100644 --- a/tests/CommandOptions/FullCrudFormRequestOptionsTest.php +++ b/tests/CommandOptions/FullCrudFormRequestOptionsTest.php @@ -12,7 +12,7 @@ class FullCrudFormRequestOptionsTest extends TestCase { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true, '--form-requests' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); @@ -25,7 +25,7 @@ class FullCrudFormRequestOptionsTest extends TestCase $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")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); diff --git a/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php b/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php index 758b7b8..7cc749e 100644 --- a/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php +++ b/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php @@ -12,7 +12,7 @@ class FullCrudFormfieldBs3OptionsTest extends TestCase { $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true, '--bs3' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); @@ -23,7 +23,7 @@ class FullCrudFormfieldBs3OptionsTest extends TestCase $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")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); diff --git a/tests/CommandOptions/FullCrudFormfieldOptionsTest.php b/tests/CommandOptions/FullCrudFormfieldOptionsTest.php index 262f7d2..c55cc2d 100644 --- a/tests/CommandOptions/FullCrudFormfieldOptionsTest.php +++ b/tests/CommandOptions/FullCrudFormfieldOptionsTest.php @@ -2,8 +2,8 @@ namespace Tests\CommandOptions; -use Tests\TestCase; use Illuminate\Contracts\Console\Kernel; +use Tests\TestCase; class FullCrudFormfieldOptionsTest extends TestCase { @@ -12,7 +12,7 @@ class FullCrudFormfieldOptionsTest extends TestCase { $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); @@ -23,7 +23,7 @@ class FullCrudFormfieldOptionsTest extends TestCase $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")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); @@ -243,6 +243,7 @@ class FullCrudFormfieldOptionsTest extends TestCase /** @test */ public function it_creates_correct_model_class_with_link_to_route_helper() { + config(['auth.providers.users.model' => 'App\User']); $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]); $modelPath = app_path($this->model_name.'.php'); @@ -280,6 +281,7 @@ class {$this->model_name} extends Model /** @test */ public function it_creates_correct_unit_test_class_with_link_to_route_helper() { + config(['auth.providers.users.model' => 'App\User']); $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]); $uniTestPath = base_path("tests/Unit/Models/{$this->model_name}Test.php"); diff --git a/tests/CommandOptions/SimpleCrudBs3OptionsTest.php b/tests/CommandOptions/SimpleCrudBs3OptionsTest.php index f3f7aa3..ecccb41 100644 --- a/tests/CommandOptions/SimpleCrudBs3OptionsTest.php +++ b/tests/CommandOptions/SimpleCrudBs3OptionsTest.php @@ -12,7 +12,7 @@ class SimpleCrudBs3OptionsTest extends TestCase { $this->artisan('make:crud-simple', ['name' => $this->model_name, '--bs3' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); diff --git a/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php b/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php index 2ead7b4..f7e16e1 100644 --- a/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php +++ b/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php @@ -12,7 +12,7 @@ class SimpleCrudFormfieldBs3OptionsTest extends TestCase { $this->artisan('make:crud-simple', ['name' => $this->model_name, '--formfield' => true, '--bs3' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); diff --git a/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php index 48b9386..df51ea1 100644 --- a/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php +++ b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php @@ -12,7 +12,7 @@ class SimpleCrudFormfieldOptionsTest extends TestCase { $this->artisan('make:crud-simple', ['name' => $this->model_name, '--formfield' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); diff --git a/tests/CommandOptions/TestsOnlyOptionsTest.php b/tests/CommandOptions/TestsOnlyOptionsTest.php index b89f2ec..72df453 100644 --- a/tests/CommandOptions/TestsOnlyOptionsTest.php +++ b/tests/CommandOptions/TestsOnlyOptionsTest.php @@ -17,28 +17,28 @@ class TestOnlyOptionsTest extends TestCase $output = app(Kernel::class)->output(); - $this->assertNotContains("{$this->model_name} model already exists.", $output); + $this->assertStringNotContainsString("{$this->model_name} model already exists.", $output); - $this->assertFileNotExists(app_path($this->model_name.'.php')); - $this->assertFileNotExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); + $this->assertFileDoesNotExist(app_path($this->model_name.'.php')); + $this->assertFileDoesNotExist(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->assertFileNotExists($migrationFilePath); + $this->assertFileDoesNotExist($migrationFilePath); - $this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php")); - $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); - $this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + $this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); - $this->assertFileNotExists(base_path("routes/web.php")); - $this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php")); - $this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php")); + $this->assertFileDoesNotExist(base_path("routes/web.php")); + $this->assertFileDoesNotExist(app_path("Policies/{$this->model_name}Policy.php")); + $this->assertFileDoesNotExist(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/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); - $this->assertContains('Test files generated successfully!', $output); + $this->assertStringContainsString('Test files generated successfully!', $output); } } diff --git a/tests/CrudApiMakeCommandTest.php b/tests/CrudApiMakeCommandTest.php index f2f2e19..6afc68a 100644 --- a/tests/CrudApiMakeCommandTest.php +++ b/tests/CrudApiMakeCommandTest.php @@ -11,16 +11,16 @@ class CrudApiMakeCommandTest extends TestCase { $this->artisan('make:crud-api', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output()); - $this->assertFileExists(app_path($this->model_name.'.php')); + $this->assertFileExists(app_path('Models/'.$this->model_name.'.php')); $this->assertFileExists(app_path("Http/Controllers/Api/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); $this->assertFileExists($migrationFilePath); - $this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php")); - $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); @@ -39,22 +39,21 @@ class CrudApiMakeCommandTest extends TestCase $this->artisan('make:model', ['name' => $this->model_name, '--no-interaction' => true]); $this->artisan('make:crud-api', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertContains("We will use existing {$this->model_name} model.", app(Kernel::class)->output()); - - $this->assertFileExists(app_path($this->model_name.'.php')); + $this->assertStringContainsString("We will use existing {$this->model_name} model.", app(Kernel::class)->output()); + $this->assertFileExists(app_path('Models/'.$this->model_name.'.php')); $this->assertFileExists(app_path("Http/Controllers/Api/{$this->model_name}Controller.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); - $this->assertFileNotExists($migrationFilePath); + $this->assertFileDoesNotExist($migrationFilePath); $localeConfig = config('app.locale'); - $this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + $this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); - $this->assertFileNotExists(base_path("routes/web.php")); - $this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php")); - $this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php")); - $this->assertFileNotExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); - $this->assertFileNotExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); + $this->assertFileDoesNotExist(base_path("routes/web.php")); + $this->assertFileDoesNotExist(app_path("Policies/{$this->model_name}Policy.php")); + $this->assertFileDoesNotExist(database_path("factories/{$this->model_name}Factory.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Api/Manage{$this->model_name}Test.php")); } @@ -64,24 +63,24 @@ class CrudApiMakeCommandTest extends TestCase $this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]); $this->artisan('make:crud-api', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]); - $this->assertContains("We will use existing Problem model.", app(Kernel::class)->output()); + $this->assertStringContainsString("We will use existing Problem model.", app(Kernel::class)->output()); $this->assertFileExists(app_path('Entities/Projects/Problem.php')); $this->assertFileExists(app_path("Http/Controllers/Api/ProblemController.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_problems_table.php'); - $this->assertFileNotExists($migrationFilePath); + $this->assertFileDoesNotExist($migrationFilePath); - $this->assertFileNotExists(resource_path("views/problems/index.blade.php")); - $this->assertFileNotExists(resource_path("views/problems/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/forms.blade.php")); $localeConfig = config('app.locale'); - $this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + $this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); - $this->assertFileNotExists(app_path("Policies/ProblemPolicy.php")); - $this->assertFileNotExists(database_path("factories/ProblemFactory.php")); - $this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php")); - $this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); + $this->assertFileDoesNotExist(app_path("Policies/ProblemPolicy.php")); + $this->assertFileDoesNotExist(database_path("factories/ProblemFactory.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Models/ProblemTest.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Api/ManageProblemTest.php")); $this->removeFileOrDir(app_path('Entities/Projects')); @@ -101,7 +100,7 @@ class CrudApiMakeCommandTest extends TestCase $this->artisan('make:crud-api', ['name' => $inputName, '--no-interaction' => true]); - $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); $this->assertFileExists(app_path("Http/Controllers/Api/{$modelName}Controller.php")); @@ -109,8 +108,8 @@ class CrudApiMakeCommandTest extends TestCase $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); - $this->assertFileNotExists(resource_path("views/{$tableName}/index.blade.php")); - $this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$tableName}/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); @@ -135,7 +134,7 @@ class CrudApiMakeCommandTest extends TestCase $this->artisan('make:crud-api', ['name' => $inputName, '--parent' => $parentName, '--no-interaction' => true]); - $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); $this->assertFileExists(app_path("Http/Controllers/Api/{$parentName}/{$modelName}Controller.php")); @@ -143,8 +142,8 @@ class CrudApiMakeCommandTest extends TestCase $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php'); $this->assertFileExists($migrationFilePath); - $this->assertFileNotExists(resource_path("views/{$tableName}/index.blade.php")); - $this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$tableName}/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index ebb4ca1..176f30e 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -11,9 +11,9 @@ class CrudMakeCommandTest extends TestCase { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output()); - $this->assertFileExists(app_path($this->model_name.'.php')); + $this->assertFileExists(app_path('Models/'.$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'); @@ -22,7 +22,7 @@ class CrudMakeCommandTest extends TestCase $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")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); @@ -43,7 +43,7 @@ class CrudMakeCommandTest extends TestCase $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]) ->expectsQuestion('Model file exists, are you sure to generate CRUD files?', true); - $this->assertFileExists(app_path($this->model_name.'.php')); + $this->assertFileExists(app_path('Models/'.$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'); @@ -52,7 +52,7 @@ class CrudMakeCommandTest extends TestCase $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")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); @@ -69,30 +69,30 @@ class CrudMakeCommandTest extends TestCase 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:model', ['name' => 'App/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?', false) ->expectsOutput('Problem model already exists.'); $this->assertFileExists(app_path('Entities/Projects/Problem.php')); - $this->assertFileNotExists(app_path("Http/Controllers/ProblemsController.php")); + $this->assertFileDoesNotExist(app_path("Http/Controllers/ProblemsController.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_problems_table.php'); - $this->assertFileNotExists($migrationFilePath); + $this->assertFileDoesNotExist($migrationFilePath); - $this->assertFileNotExists(resource_path("views/problems/index.blade.php")); - $this->assertFileNotExists(resource_path("views/problems/create.blade.php")); - $this->assertFileNotExists(resource_path("views/problems/edit.blade.php")); - $this->assertFileNotExists(resource_path("views/problems/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/create.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/edit.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/forms.blade.php")); $localeConfig = config('app.locale'); - $this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + $this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); - $this->assertFileNotExists(app_path("Policies/ProblemPolicy.php")); - $this->assertFileNotExists(database_path("factories/ProblemFactory.php")); - $this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php")); - $this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); - $this->assertFileNotExists(base_path("tests/Feature/ManageProblemTest.php")); + $this->assertFileDoesNotExist(app_path("Policies/ProblemPolicy.php")); + $this->assertFileDoesNotExist(database_path("factories/ProblemFactory.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Models/ProblemTest.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); + $this->assertFileDoesNotExist(base_path("tests/Feature/ManageProblemTest.php")); $this->removeFileOrDir(app_path('Entities/Projects')); $this->removeFileOrDir(resource_path('views/problems')); @@ -111,7 +111,7 @@ class CrudMakeCommandTest extends TestCase $this->artisan('make:crud', ['name' => $inputName, '--no-interaction' => true]); - $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); $this->assertFileExists(app_path("Http/Controllers/{$modelName}Controller.php")); @@ -122,7 +122,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(resource_path("views/{$tableName}/index.blade.php")); $this->assertFileExists(resource_path("views/{$tableName}/create.blade.php")); $this->assertFileExists(resource_path("views/{$tableName}/edit.blade.php")); - $this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); @@ -147,7 +147,7 @@ class CrudMakeCommandTest extends TestCase $this->artisan('make:crud', ['name' => $inputName, '--parent' => $parentName, '--no-interaction' => true]); - $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); $this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$modelName}Controller.php")); @@ -158,7 +158,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(resource_path("views/{$tableName}/index.blade.php")); $this->assertFileExists(resource_path("views/{$tableName}/create.blade.php")); $this->assertFileExists(resource_path("views/{$tableName}/edit.blade.php")); - $this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php")); $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php")); diff --git a/tests/CrudSimpleMakeCommandTest.php b/tests/CrudSimpleMakeCommandTest.php index 9ac980f..279711a 100644 --- a/tests/CrudSimpleMakeCommandTest.php +++ b/tests/CrudSimpleMakeCommandTest.php @@ -11,7 +11,7 @@ class CrudSimpleCommandTest extends TestCase { $this->artisan('make:crud-simple', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$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")); @@ -43,51 +43,51 @@ class CrudSimpleCommandTest extends TestCase ->expectsOutput("{$this->model_name} model already exists."); $this->assertFileExists(app_path($this->model_name.'.php')); - $this->assertFileNotExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); + $this->assertFileDoesNotExist(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->assertFileNotExists($migrationFilePath); + $this->assertFileDoesNotExist($migrationFilePath); - $this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php")); - $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php")); $localeConfig = config('app.locale'); - $this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); - - $this->assertFileNotExists(base_path("routes/web.php")); - $this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php")); - $this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php")); - $this->assertFileNotExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); - $this->assertFileNotExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); - $this->assertFileNotExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); + $this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + + $this->assertFileDoesNotExist(base_path("routes/web.php")); + $this->assertFileDoesNotExist(app_path("Policies/{$this->model_name}Policy.php")); + $this->assertFileDoesNotExist(database_path("factories/{$this->model_name}Factory.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); + $this->assertFileDoesNotExist(base_path("tests/Feature/Manage{$this->model_name}Test.php")); } /** @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:model', ['name' => 'App/Entities/Projects/Problem', '--no-interaction' => true]); $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")); + $this->assertFileDoesNotExist(app_path("Http/Controllers/ProblemsController.php")); $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_problems_table.php'); - $this->assertFileNotExists($migrationFilePath); + $this->assertFileDoesNotExist($migrationFilePath); - $this->assertFileNotExists(resource_path("views/problems/index.blade.php")); - $this->assertFileNotExists(resource_path("views/problems/forms.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/index.blade.php")); + $this->assertFileDoesNotExist(resource_path("views/problems/forms.blade.php")); $localeConfig = config('app.locale'); - $this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + $this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); - $this->assertFileNotExists(app_path("Policies/ProblemPolicy.php")); - $this->assertFileNotExists(database_path("factories/ProblemFactory.php")); - $this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php")); - $this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); - $this->assertFileNotExists(base_path("tests/Feature/ManageProblemTest.php")); + $this->assertFileDoesNotExist(app_path("Policies/ProblemPolicy.php")); + $this->assertFileDoesNotExist(database_path("factories/ProblemFactory.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Models/ProblemTest.php")); + $this->assertFileDoesNotExist(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); + $this->assertFileDoesNotExist(base_path("tests/Feature/ManageProblemTest.php")); $this->removeFileOrDir(app_path('Entities/Projects')); $this->removeFileOrDir(resource_path('views/problems')); @@ -106,7 +106,7 @@ class CrudSimpleCommandTest extends TestCase $this->artisan('make:crud-simple', ['name' => $inputName, '--no-interaction' => true]); - $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); $this->assertFileExists(app_path("Http/Controllers/{$modelName}Controller.php")); @@ -140,7 +140,7 @@ class CrudSimpleCommandTest extends TestCase $this->artisan('make:crud-simple', ['name' => $inputName, '--parent' => $parentName, '--no-interaction' => true]); - $this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output()); + $this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output()); $this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php')); $this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$modelName}Controller.php")); diff --git a/tests/Generators/ModelGeneratorTest.php b/tests/Generators/ModelGeneratorTest.php index 5293bf6..d2190d1 100644 --- a/tests/Generators/ModelGeneratorTest.php +++ b/tests/Generators/ModelGeneratorTest.php @@ -15,13 +15,16 @@ class ModelGeneratorTest extends TestCase $this->assertFileExists($modelPath); $modelClassContent = "model_name} extends Model { + use HasFactory; + protected \$fillable = ['name', 'description', 'creator_id']; public function getNameLinkAttribute() @@ -58,10 +61,13 @@ class {$this->model_name} extends Model namespace App\Entities\References; use App\User; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Category extends Model { + use HasFactory; + protected \$fillable = ['name', 'description', 'creator_id']; public function getNameLinkAttribute() diff --git a/tests/Generators/Simple/ViewsGeneratorTest.php b/tests/Generators/Simple/ViewsGeneratorTest.php index 0d36c1b..d470af6 100644 --- a/tests/Generators/Simple/ViewsGeneratorTest.php +++ b/tests/Generators/Simple/ViewsGeneratorTest.php @@ -167,7 +167,7 @@ class ViewsGeneratorTest extends TestCase $this->artisan('make:crud-simple', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertNotRegExp("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); + $this->assertDoesNotMatchRegularExpression("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); } /** @test */ @@ -176,7 +176,7 @@ class ViewsGeneratorTest extends TestCase $this->artisan('make:crud-simple', ['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()); + $this->assertMatchesRegularExpression("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); } public function generateDefaultLayoutView($defaultLayoutView) diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php index d30fd36..3d062ef 100644 --- a/tests/Generators/ViewsGeneratorTest.php +++ b/tests/Generators/ViewsGeneratorTest.php @@ -234,7 +234,7 @@ class ViewsGeneratorTest extends TestCase $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); - $this->assertNotRegExp("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); + $this->assertDoesNotMatchRegularExpression("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); } /** @test */ @@ -243,7 +243,7 @@ class ViewsGeneratorTest extends TestCase $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()); + $this->assertMatchesRegularExpression("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); } public function generateDefaultLayoutView($defaultLayoutView)