diff --git a/src/stubs/controllers/full-formrequests.stub b/src/stubs/controllers/full-formrequests.stub index 31ddce3..8a2b08f 100644 --- a/src/stubs/controllers/full-formrequests.stub +++ b/src/stubs/controllers/full-formrequests.stub @@ -51,7 +51,7 @@ class MasterController extends Controller /** * Display the specified singleMstr. * - * @param \App\Master $singleMstr + * @param \App\Models\Master $singleMstr * @return \Illuminate\View\View */ public function show(Master $singleMstr) @@ -62,7 +62,7 @@ class MasterController extends Controller /** * Show the form for editing the specified singleMstr. * - * @param \App\Master $singleMstr + * @param \App\Models\Master $singleMstr * @return \Illuminate\View\View */ public function edit(Master $singleMstr) diff --git a/src/stubs/controllers/full.stub b/src/stubs/controllers/full.stub index 37424b7..41ca598 100644 --- a/src/stubs/controllers/full.stub +++ b/src/stubs/controllers/full.stub @@ -57,7 +57,7 @@ class MasterController extends Controller /** * Display the specified singleMstr. * - * @param \App\Master $singleMstr + * @param \App\Models\Master $singleMstr * @return \Illuminate\View\View */ public function show(Master $singleMstr) @@ -68,7 +68,7 @@ class MasterController extends Controller /** * Show the form for editing the specified singleMstr. * - * @param \App\Master $singleMstr + * @param \App\Models\Master $singleMstr * @return \Illuminate\View\View */ public function edit(Master $singleMstr) diff --git a/tests/CommandOptions/FullCrudBs3OptionsTest.php b/tests/CommandOptions/FullCrudBs3OptionsTest.php index 5b52aa4..cfb9d5d 100644 --- a/tests/CommandOptions/FullCrudBs3OptionsTest.php +++ b/tests/CommandOptions/FullCrudBs3OptionsTest.php @@ -2,8 +2,8 @@ namespace Tests\CommandOptions; -use Tests\TestCase; use Illuminate\Contracts\Console\Kernel; +use Tests\TestCase; class FullCrudBs3OptionsTest extends TestCase { @@ -14,7 +14,7 @@ class FullCrudBs3OptionsTest extends TestCase $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'); diff --git a/tests/CommandOptions/FullCrudFormRequestOptionsTest.php b/tests/CommandOptions/FullCrudFormRequestOptionsTest.php index fe303fe..a2420c6 100644 --- a/tests/CommandOptions/FullCrudFormRequestOptionsTest.php +++ b/tests/CommandOptions/FullCrudFormRequestOptionsTest.php @@ -2,8 +2,8 @@ namespace Tests\CommandOptions; -use Tests\TestCase; use Illuminate\Contracts\Console\Kernel; +use Tests\TestCase; class FullCrudFormRequestOptionsTest extends TestCase { @@ -14,7 +14,7 @@ class FullCrudFormRequestOptionsTest extends TestCase $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")); $this->assertFileExists(app_path("Http/Requests/{$this->plural_model_name}/CreateRequest.php")); $this->assertFileExists(app_path("Http/Requests/{$this->plural_model_name}/UpdateRequest.php")); diff --git a/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php b/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php index 7cc749e..745ff7b 100644 --- a/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php +++ b/tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php @@ -2,8 +2,8 @@ namespace Tests\CommandOptions; -use Tests\TestCase; use Illuminate\Contracts\Console\Kernel; +use Tests\TestCase; class FullCrudFormfieldBs3OptionsTest extends TestCase { @@ -14,7 +14,7 @@ class FullCrudFormfieldBs3OptionsTest extends TestCase $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'); diff --git a/tests/CommandOptions/FullCrudFormfieldOptionsTest.php b/tests/CommandOptions/FullCrudFormfieldOptionsTest.php index c55cc2d..f646a86 100644 --- a/tests/CommandOptions/FullCrudFormfieldOptionsTest.php +++ b/tests/CommandOptions/FullCrudFormfieldOptionsTest.php @@ -14,7 +14,7 @@ class FullCrudFormfieldOptionsTest extends TestCase $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'); @@ -243,20 +243,23 @@ class FullCrudFormfieldOptionsTest extends TestCase /** @test */ public function it_creates_correct_model_class_with_link_to_route_helper() { - config(['auth.providers.users.model' => 'App\User']); + config(['auth.providers.users.model' => 'App\Models\User']); $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]); - $modelPath = app_path($this->model_name.'.php'); + $modelPath = app_path('Models/'.$this->model_name.'.php'); $this->assertFileExists($modelPath); $modelClassContent = "model_name} extends Model { + use HasFactory; + protected \$fillable = ['name', 'description', 'creator_id']; public function getNameLinkAttribute() @@ -302,7 +305,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_name_link_attribute() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertEquals( link_to_route('{$this->table_name}.show', \${$this->single_model_var_name}->name, [\${$this->single_model_var_name}], [ @@ -317,7 +320,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_belongs_to_creator_relation() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->make(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->make(); \$this->assertInstanceOf(User::class, \${$this->single_model_var_name}->creator); \$this->assertEquals(\${$this->single_model_var_name}->creator_id, \${$this->single_model_var_name}->creator->id); diff --git a/tests/CommandOptions/SimpleCrudBs3OptionsTest.php b/tests/CommandOptions/SimpleCrudBs3OptionsTest.php index ecccb41..74b99bc 100644 --- a/tests/CommandOptions/SimpleCrudBs3OptionsTest.php +++ b/tests/CommandOptions/SimpleCrudBs3OptionsTest.php @@ -2,8 +2,8 @@ namespace Tests\CommandOptions; -use Tests\TestCase; use Illuminate\Contracts\Console\Kernel; +use Tests\TestCase; class SimpleCrudBs3OptionsTest extends TestCase { @@ -14,7 +14,7 @@ class SimpleCrudBs3OptionsTest extends TestCase $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'); diff --git a/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php b/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php index f7e16e1..7d65084 100644 --- a/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php +++ b/tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php @@ -2,8 +2,8 @@ namespace Tests\CommandOptions; -use Tests\TestCase; use Illuminate\Contracts\Console\Kernel; +use Tests\TestCase; class SimpleCrudFormfieldBs3OptionsTest extends TestCase { @@ -14,7 +14,7 @@ class SimpleCrudFormfieldBs3OptionsTest extends TestCase $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'); diff --git a/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php index df51ea1..48a61d4 100644 --- a/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php +++ b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php @@ -2,8 +2,8 @@ namespace Tests\CommandOptions; -use Tests\TestCase; use Illuminate\Contracts\Console\Kernel; +use Tests\TestCase; class SimpleCrudFormfieldOptionsTest extends TestCase { @@ -14,7 +14,7 @@ class SimpleCrudFormfieldOptionsTest extends TestCase $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'); diff --git a/tests/CrudApiMakeCommandTest.php b/tests/CrudApiMakeCommandTest.php index 6afc68a..60a5360 100644 --- a/tests/CrudApiMakeCommandTest.php +++ b/tests/CrudApiMakeCommandTest.php @@ -36,7 +36,7 @@ class CrudApiMakeCommandTest extends TestCase /** @test */ public function it_generate_api_crud_files_even_if_model_exists() { - $this->artisan('make:model', ['name' => $this->model_name, '--no-interaction' => true]); + $this->artisan('make:model', ['name' => 'Models/'.$this->model_name, '--no-interaction' => true]); $this->artisan('make:crud-api', ['name' => $this->model_name, '--no-interaction' => true]); $this->assertStringContainsString("We will use existing {$this->model_name} model.", app(Kernel::class)->output()); diff --git a/tests/CrudMakeClassPropertiesTest.php b/tests/CrudMakeClassPropertiesTest.php index afe12f7..49be9d1 100644 --- a/tests/CrudMakeClassPropertiesTest.php +++ b/tests/CrudMakeClassPropertiesTest.php @@ -16,14 +16,14 @@ class CrudMakeClassPropertiesTest extends TestCase public function it_has_stub_model_names_property() { $this->assertEquals([ - 'model_namespace' => 'mstrNmspc', - 'full_model_name' => 'fullMstr', - 'plural_model_name' => 'Masters', - 'model_name' => 'Master', - 'table_name' => 'masters', - 'lang_name' => 'master', + 'model_namespace' => 'mstrNmspc', + 'full_model_name' => 'fullMstr', + 'plural_model_name' => 'Masters', + 'model_name' => 'Master', + 'table_name' => 'masters', + 'lang_name' => 'master', 'collection_model_var_name' => 'mstrCollections', - 'single_model_var_name' => 'singleMstr', + 'single_model_var_name' => 'singleMstr', ], $this->crudMaker->stubModelNames); } @@ -31,27 +31,27 @@ class CrudMakeClassPropertiesTest extends TestCase public function it_has_model_names_property() { $this->assertEquals([ - 'full_model_name' => 'App\Category', - 'plural_model_name' => 'Categories', - 'model_name' => 'Category', - 'table_name' => 'categories', - 'lang_name' => 'category', + 'full_model_name' => 'App\Models\Category', + 'plural_model_name' => 'Categories', + 'model_name' => 'Category', + 'table_name' => 'categories', + 'lang_name' => 'category', 'collection_model_var_name' => 'categories', - 'single_model_var_name' => 'category', - 'model_path' => '', - 'model_namespace' => 'App', + 'single_model_var_name' => 'category', + 'model_path' => 'Models', + 'model_namespace' => 'App\Models', ], $this->crudMaker->getModelName('Category')); $this->assertEquals([ - 'full_model_name' => 'App\Category', - 'plural_model_name' => 'Categories', - 'model_name' => 'Category', - 'table_name' => 'categories', - 'lang_name' => 'category', + 'full_model_name' => 'App\Models\Category', + 'plural_model_name' => 'Categories', + 'model_name' => 'Category', + 'table_name' => 'categories', + 'lang_name' => 'category', 'collection_model_var_name' => 'categories', - 'single_model_var_name' => 'category', - 'model_path' => '', - 'model_namespace' => 'App', + 'single_model_var_name' => 'category', + 'model_path' => 'Models', + 'model_namespace' => 'App\Models', ], $this->crudMaker->getModelName('category')); } @@ -59,39 +59,39 @@ class CrudMakeClassPropertiesTest extends TestCase public function it_set_proper_model_names_property_for_namespaced_model_name_entry() { $this->assertEquals([ - 'model_namespace' => 'App\Entities\References', - 'full_model_name' => 'App\Entities\References\Category', - 'plural_model_name' => 'Categories', - 'model_name' => 'Category', - 'table_name' => 'categories', - 'lang_name' => 'category', + 'model_namespace' => 'App\Entities\References', + 'full_model_name' => 'App\Entities\References\Category', + 'plural_model_name' => 'Categories', + 'model_name' => 'Category', + 'table_name' => 'categories', + 'lang_name' => 'category', 'collection_model_var_name' => 'categories', - 'single_model_var_name' => 'category', - 'model_path' => 'Entities/References', + 'single_model_var_name' => 'category', + 'model_path' => 'Entities/References', ], $this->crudMaker->getModelName('Entities/References/Category')); $this->assertEquals([ - 'model_namespace' => 'App\Models', - 'full_model_name' => 'App\Models\Category', - 'plural_model_name' => 'Categories', - 'model_name' => 'Category', - 'table_name' => 'categories', - 'lang_name' => 'category', + 'model_namespace' => 'App\Models', + 'full_model_name' => 'App\Models\Category', + 'plural_model_name' => 'Categories', + 'model_name' => 'Category', + 'table_name' => 'categories', + 'lang_name' => 'category', 'collection_model_var_name' => 'categories', - 'single_model_var_name' => 'category', - 'model_path' => 'Models', + 'single_model_var_name' => 'category', + 'model_path' => 'Models', ], $this->crudMaker->getModelName('Models/Category')); $this->assertEquals([ - 'model_namespace' => 'App\Models', - 'full_model_name' => 'App\Models\Category', - 'plural_model_name' => 'Categories', - 'model_name' => 'Category', - 'table_name' => 'categories', - 'lang_name' => 'category', + 'model_namespace' => 'App\Models', + 'full_model_name' => 'App\Models\Category', + 'plural_model_name' => 'Categories', + 'model_name' => 'Category', + 'table_name' => 'categories', + 'lang_name' => 'category', 'collection_model_var_name' => 'categories', - 'single_model_var_name' => 'category', - 'model_path' => 'Models', + 'single_model_var_name' => 'category', + 'model_path' => 'Models', ], $this->crudMaker->getModelName('models/category')); } } diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index 176f30e..d34c46f 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -39,7 +39,7 @@ class CrudMakeCommandTest extends TestCase public function it_generates_crud_files_for_existing_model() { $this->mockConsoleOutput = true; - $this->artisan('make:model', ['name' => $this->model_name, '--no-interaction' => true]); + $this->artisan('make:model', ['name' => 'Models/'.$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?', true); diff --git a/tests/CrudSimpleMakeCommandTest.php b/tests/CrudSimpleMakeCommandTest.php index 279711a..1844fea 100644 --- a/tests/CrudSimpleMakeCommandTest.php +++ b/tests/CrudSimpleMakeCommandTest.php @@ -13,7 +13,7 @@ class CrudSimpleCommandTest extends TestCase $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'); @@ -37,12 +37,12 @@ class CrudSimpleCommandTest extends TestCase public function it_cannot_generate_crud_files_if_model_exists() { $this->mockConsoleOutput = true; - $this->artisan('make:model', ['name' => $this->model_name, '--no-interaction' => true]); + $this->artisan('make:model', ['name' => 'Models/'.$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?', false) ->expectsOutput("{$this->model_name} model already exists."); - $this->assertFileExists(app_path($this->model_name.'.php')); + $this->assertFileExists(app_path('Models/'.$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'); diff --git a/tests/Generators/Api/ApiFeatureTestGeneratorTest.php b/tests/Generators/Api/ApiFeatureTestGeneratorTest.php index a93c1fe..b0fecb1 100644 --- a/tests/Generators/Api/ApiFeatureTestGeneratorTest.php +++ b/tests/Generators/Api/ApiFeatureTestGeneratorTest.php @@ -28,7 +28,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->getJson(route('api.{$this->table_name}.index'), [ 'Authorization' => 'Bearer '.\$user->api_token @@ -125,7 +125,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_get_a_{$this->lang_name}_detail() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->getJson(route('api.{$this->table_name}.show', \${$this->single_model_var_name}), [ 'Authorization' => 'Bearer '.\$user->api_token @@ -138,7 +138,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_update_a_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->patchJson(route('api.{$this->table_name}.update', \${$this->single_model_var_name}), [ 'name' => '{$this->model_name} 1 name', @@ -172,7 +172,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_required() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); // name empty \$requestBody = \$this->getEditFields(['name' => '']); @@ -190,7 +190,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); // name 70 characters \$requestBody = \$this->getEditFields(['name' => str_repeat('Test Title', 7)]); @@ -208,7 +208,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // description 256 characters \$requestBody = \$this->getEditFields(['description' => str_repeat('Long description', 16)]); @@ -226,7 +226,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_delete_a_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->deleteJson(route('api.{$this->table_name}.destroy', \${$this->single_model_var_name}), [ '{$this->lang_name}_id' => \${$this->single_model_var_name}->id, @@ -273,7 +273,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->getJson(route('api.{$this->table_name}.index'), [ 'Authorization' => 'Bearer '.\$user->api_token @@ -370,7 +370,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_get_a_{$this->lang_name}_detail() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->getJson(route('api.{$this->table_name}.show', \${$this->single_model_var_name}), [ 'Authorization' => 'Bearer '.\$user->api_token @@ -383,7 +383,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_update_a_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->patchJson(route('api.{$this->table_name}.update', \${$this->single_model_var_name}), [ 'name' => '{$this->model_name} 1 name', @@ -417,7 +417,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_required() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); // name empty \$requestBody = \$this->getEditFields(['name' => '']); @@ -435,7 +435,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); // name 70 characters \$requestBody = \$this->getEditFields(['name' => str_repeat('Test Title', 7)]); @@ -453,7 +453,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // description 256 characters \$requestBody = \$this->getEditFields(['description' => str_repeat('Long description', 16)]); @@ -471,7 +471,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_delete_a_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->deleteJson(route('api.{$this->table_name}.destroy', \${$this->single_model_var_name}), [ '{$this->lang_name}_id' => \${$this->single_model_var_name}->id, diff --git a/tests/Generators/Api/RouteApiGeneratorTest.php b/tests/Generators/Api/RouteApiGeneratorTest.php index 9e1aa4b..aab7c6d 100644 --- a/tests/Generators/Api/RouteApiGeneratorTest.php +++ b/tests/Generators/Api/RouteApiGeneratorTest.php @@ -18,7 +18,7 @@ class RouteApiGeneratorTest extends TestCase /* * {$this->plural_model_name} Endpoints */ -Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\{$this->model_name}Controller')->names('api.{$this->table_name}'); +Route::middleware('auth:api')->resource('{$this->table_name}', App\\Http\\Controllers\\Api\\{$this->model_name}Controller::class)->names('api.{$this->table_name}'); "; $this->assertEquals($routeApiFileContent, file_get_contents($routeApiPath)); } @@ -35,7 +35,7 @@ Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\{$this->mod /* * {$this->plural_model_name} Endpoints */ -Route::middleware('auth:api')->resource('{$this->table_name}', 'Api\\Projects\\{$this->model_name}Controller')->names('api.{$this->table_name}'); +Route::middleware('auth:api')->resource('{$this->table_name}', App\\Http\\Controllers\\Api\\Projects\\{$this->model_name}Controller::class)->names('api.{$this->table_name}'); "; $this->assertEquals($routeApiFileContent, file_get_contents($routeApiPath)); } diff --git a/tests/Generators/FeatureTestGeneratorTest.php b/tests/Generators/FeatureTestGeneratorTest.php index 2780f24..a9ac2b7 100644 --- a/tests/Generators/FeatureTestGeneratorTest.php +++ b/tests/Generators/FeatureTestGeneratorTest.php @@ -16,7 +16,7 @@ class FeatureTestGeneratorTest extends TestCase namespace Tests; -use App\User; +use App\Models\User; use Laravel\BrowserKitTesting\TestCase as BaseTestCase; abstract class BrowserKitTest extends BaseTestCase @@ -35,7 +35,7 @@ abstract class BrowserKitTest extends BaseTestCase protected function createUser() { - return factory(User::class)->create(); + return User::factory()->create(); } } "; @@ -63,7 +63,7 @@ class Manage{$this->model_name}Test extends TestCase /** @test */ public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->loginAsUser(); \$this->visitRoute('{$this->table_name}.index'); @@ -140,7 +140,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_edit_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->visitRoute('{$this->table_name}.show', \${$this->single_model_var_name}); \$this->click('edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -159,7 +159,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_required() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name empty \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields(['name' => ''])); @@ -170,7 +170,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name 70 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -183,7 +183,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // description 256 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -196,8 +196,8 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_delete_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); - factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); + {$this->model_name}::factory()->create(); \$this->visitRoute('{$this->table_name}.edit', \${$this->single_model_var_name}); \$this->click('del-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -230,7 +230,7 @@ class Manage{$this->model_name}Test extends TestCase namespace Tests; -use App\User; +use App\Models\User; use Laravel\BrowserKitTesting\TestCase as BaseTestCase; abstract class {$baseTestClass} extends BaseTestCase @@ -249,7 +249,7 @@ abstract class {$baseTestClass} extends BaseTestCase protected function createUser() { - return factory(User::class)->create(); + return User::factory()->create(); } } "; @@ -280,7 +280,7 @@ class Manage{$this->model_name}Test extends TestCase /** @test */ public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->loginAsUser(); \$this->visitRoute('{$this->table_name}.index'); @@ -357,7 +357,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_edit_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->visitRoute('{$this->table_name}.show', \${$this->single_model_var_name}); \$this->click('edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -376,7 +376,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_required() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name empty \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields(['name' => ''])); @@ -387,7 +387,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name 70 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -400,7 +400,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // description 256 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -413,8 +413,8 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_delete_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); - factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); + {$this->model_name}::factory()->create(); \$this->visitRoute('{$this->table_name}.edit', \${$this->single_model_var_name}); \$this->click('del-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -455,7 +455,7 @@ class Manage{$this->model_name}Test extends TestCase /** @test */ public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->loginAsUser(); \$this->visitRoute('{$this->table_name}.index'); @@ -532,7 +532,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_edit_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->visitRoute('{$this->table_name}.show', \${$this->single_model_var_name}); \$this->click('edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -551,7 +551,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_required() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name empty \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields(['name' => ''])); @@ -562,7 +562,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name 70 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -575,7 +575,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // description 256 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -588,8 +588,8 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_delete_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); - factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); + {$this->model_name}::factory()->create(); \$this->visitRoute('{$this->table_name}.edit', \${$this->single_model_var_name}); \$this->click('del-{$this->lang_name}-'.\${$this->single_model_var_name}->id); diff --git a/tests/Generators/FullControllerGeneratorTest.php b/tests/Generators/FullControllerGeneratorTest.php index 0d807dc..b672dcc 100644 --- a/tests/Generators/FullControllerGeneratorTest.php +++ b/tests/Generators/FullControllerGeneratorTest.php @@ -201,7 +201,7 @@ class CategoryController extends Controller /** * Display the specified category. * - * @param \App\Category \$category + * @param \App\Models\Category \$category * @return \Illuminate\View\View */ public function show(Category \$category) @@ -212,7 +212,7 @@ class CategoryController extends Controller /** * Show the form for editing the specified category. * - * @param \App\Category \$category + * @param \App\Models\Category \$category * @return \Illuminate\View\View */ public function edit(Category \$category) @@ -332,7 +332,7 @@ class CategoryController extends Controller /** * Display the specified category. * - * @param \App\Category \$category + * @param \App\Models\Category \$category * @return \Illuminate\View\View */ public function show(Category \$category) @@ -343,7 +343,7 @@ class CategoryController extends Controller /** * Show the form for editing the specified category. * - * @param \App\Category \$category + * @param \App\Models\Category \$category * @return \Illuminate\View\View */ public function edit(Category \$category) diff --git a/tests/Generators/ModelFactoryGeneratorTest.php b/tests/Generators/ModelFactoryGeneratorTest.php index d93b37b..eb9e362 100644 --- a/tests/Generators/ModelFactoryGeneratorTest.php +++ b/tests/Generators/ModelFactoryGeneratorTest.php @@ -15,21 +15,27 @@ class ModelFactoryGeneratorTest extends TestCase $this->assertFileExists($modelFactoryPath); $modelFactoryContent = "full_model_name}; -use Faker\Generator as Faker; - -\$factory->define({$this->model_name}::class, function (Faker \$faker) { - - return [ - 'name' => \$faker->word, - 'description' => \$faker->sentence, - 'creator_id' => function () { - return factory(User::class)->create()->id; - }, - ]; -}); -"; +use Illuminate\Database\Eloquent\Factories\Factory; + +class {$this->model_name}Factory extends Factory +{ + protected \$model = {$this->model_name}::class; + + public function definition() + { + return [ + 'name' => \$this->faker->word, + 'description' => \$this->faker->sentence, + 'creator_id' => function () { + return User::factory()->create()->id; + }, + ]; + } +}"; $this->assertEquals($modelFactoryContent, file_get_contents($modelFactoryPath)); } } diff --git a/tests/Generators/ModelGeneratorTest.php b/tests/Generators/ModelGeneratorTest.php index d2190d1..d333e3f 100644 --- a/tests/Generators/ModelGeneratorTest.php +++ b/tests/Generators/ModelGeneratorTest.php @@ -9,9 +9,10 @@ class ModelGeneratorTest extends TestCase /** @test */ public function it_creates_correct_model_class_content() { + config(['auth.providers.users.model' => 'App\Models\User']); $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); - $modelPath = app_path($this->model_name.'.php'); + $modelPath = app_path('Models/'.$this->model_name.'.php'); $this->assertFileExists($modelPath); $modelClassContent = "model_name} extends Model /** @test */ public function it_creates_correct_namespaced_model_class_content() { + config(['auth.providers.users.model' => 'App\Models\User']); $this->artisan('make:crud', ['name' => 'Entities/References/Category', '--no-interaction' => true]); $modelPath = app_path('Entities/References/Category.php'); @@ -60,7 +62,7 @@ class {$this->model_name} extends Model namespace App\Entities\References; -use App\User; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; diff --git a/tests/Generators/ModelPolicyTestGeneratorTest.php b/tests/Generators/ModelPolicyTestGeneratorTest.php index 1412f1a..1cbc680 100644 --- a/tests/Generators/ModelPolicyTestGeneratorTest.php +++ b/tests/Generators/ModelPolicyTestGeneratorTest.php @@ -39,7 +39,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_view_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('view', \${$this->single_model_var_name})); } @@ -47,7 +47,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_update_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('update', \${$this->single_model_var_name})); } @@ -55,7 +55,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_delete_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('delete', \${$this->single_model_var_name})); } } @@ -99,7 +99,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_view_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('view', \${$this->single_model_var_name})); } @@ -107,7 +107,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_update_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('update', \${$this->single_model_var_name})); } @@ -115,7 +115,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_delete_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('delete', \${$this->single_model_var_name})); } } @@ -159,7 +159,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_view_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('view', \${$this->single_model_var_name})); } @@ -167,7 +167,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_update_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('update', \${$this->single_model_var_name})); } @@ -175,7 +175,7 @@ class {$this->model_name}PolicyTest extends TestCase public function user_can_delete_{$this->lang_name}() { \$user = \$this->createUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->assertTrue(\$user->can('delete', \${$this->single_model_var_name})); } } diff --git a/tests/Generators/ModelTestGeneratorTest.php b/tests/Generators/ModelTestGeneratorTest.php index 824fe07..5db0bd0 100644 --- a/tests/Generators/ModelTestGeneratorTest.php +++ b/tests/Generators/ModelTestGeneratorTest.php @@ -9,6 +9,7 @@ class ModelTestGeneratorTest extends TestCase /** @test */ public function it_creates_correct_unit_test_class_content() { + config(['auth.providers.users.model' => 'App\Models\User']); $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $uniTestPath = base_path("tests/Unit/Models/{$this->model_name}Test.php"); @@ -17,7 +18,7 @@ class ModelTestGeneratorTest extends TestCase namespace Tests\Unit\Models; -use App\User; +use App\Models\User; use {$this->full_model_name}; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\BrowserKitTest as TestCase; @@ -29,7 +30,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_name_link_attribute() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$title = __('app.show_detail_title', [ 'name' => \${$this->single_model_var_name}->name, 'type' => __('{$this->lang_name}.{$this->lang_name}'), @@ -45,7 +46,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_belongs_to_creator_relation() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->make(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->make(); \$this->assertInstanceOf(User::class, \${$this->single_model_var_name}->creator); \$this->assertEquals(\${$this->single_model_var_name}->creator_id, \${$this->single_model_var_name}->creator->id); @@ -58,6 +59,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function it_creates_correct_unit_test_class_with_base_test_class_based_on_config_file() { + config(['auth.providers.users.model' => 'App\Models\User']); config(['simple-crud.base_test_path' => 'tests/MyTestCase.php']); config(['simple-crud.base_test_class' => 'Tests\MyTestCase']); @@ -69,7 +71,7 @@ class {$this->model_name}Test extends TestCase namespace Tests\Unit\Models; -use App\User; +use App\Models\User; use {$this->full_model_name}; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\MyTestCase as TestCase; @@ -81,7 +83,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_name_link_attribute() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$title = __('app.show_detail_title', [ 'name' => \${$this->single_model_var_name}->name, 'type' => __('{$this->lang_name}.{$this->lang_name}'), @@ -97,7 +99,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_belongs_to_creator_relation() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->make(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->make(); \$this->assertInstanceOf(User::class, \${$this->single_model_var_name}->creator); \$this->assertEquals(\${$this->single_model_var_name}->creator_id, \${$this->single_model_var_name}->creator->id); @@ -110,6 +112,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function same_base_test_case_class_name_dont_use_alias() { + config(['auth.providers.users.model' => 'App\Models\User']); config(['simple-crud.base_test_path' => 'tests/TestCase.php']); config(['simple-crud.base_test_class' => 'Tests\TestCase']); @@ -121,7 +124,7 @@ class {$this->model_name}Test extends TestCase namespace Tests\Unit\Models; -use App\User; +use App\Models\User; use {$this->full_model_name}; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -133,7 +136,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_name_link_attribute() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$title = __('app.show_detail_title', [ 'name' => \${$this->single_model_var_name}->name, 'type' => __('{$this->lang_name}.{$this->lang_name}'), @@ -149,7 +152,7 @@ class {$this->model_name}Test extends TestCase /** @test */ public function a_{$this->lang_name}_has_belongs_to_creator_relation() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->make(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->make(); \$this->assertInstanceOf(User::class, \${$this->single_model_var_name}->creator); \$this->assertEquals(\${$this->single_model_var_name}->creator_id, \${$this->single_model_var_name}->creator->id); diff --git a/tests/Generators/RouteWebGeneratorTest.php b/tests/Generators/RouteWebGeneratorTest.php index 8901b1e..977133d 100644 --- a/tests/Generators/RouteWebGeneratorTest.php +++ b/tests/Generators/RouteWebGeneratorTest.php @@ -18,7 +18,7 @@ class RouteWebGeneratorTest extends TestCase /* * {$this->plural_model_name} Routes */ -Route::resource('{$this->table_name}', '{$this->model_name}Controller'); +Route::resource('{$this->table_name}', App\\Http\\Controllers\\{$this->model_name}Controller::class); "; $this->assertEquals($routeWebFileContent, file_get_contents($routeWebPath)); } @@ -35,7 +35,7 @@ Route::resource('{$this->table_name}', '{$this->model_name}Controller'); /* * {$this->plural_model_name} Routes */ -Route::resource('{$this->table_name}', 'Projects\\{$this->model_name}Controller'); +Route::resource('{$this->table_name}', App\\Http\\Controllers\\Projects\\{$this->model_name}Controller::class); "; $this->assertEquals($routeWebFileContent, file_get_contents($routeWebPath)); } diff --git a/tests/Generators/Simple/FeatureTestGeneratorTest.php b/tests/Generators/Simple/FeatureTestGeneratorTest.php index 41aaa41..9c41a7e 100644 --- a/tests/Generators/Simple/FeatureTestGeneratorTest.php +++ b/tests/Generators/Simple/FeatureTestGeneratorTest.php @@ -16,7 +16,7 @@ class FeatureTestGeneratorTest extends TestCase namespace Tests; -use App\User; +use App\Models\User; use Laravel\BrowserKitTesting\TestCase as BaseTestCase; abstract class BrowserKitTest extends BaseTestCase @@ -35,7 +35,7 @@ abstract class BrowserKitTest extends BaseTestCase protected function createUser() { - return factory(User::class)->create(); + return User::factory()->create(); } } "; @@ -63,7 +63,7 @@ class Manage{$this->model_name}Test extends TestCase /** @test */ public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->loginAsUser(); \$this->visitRoute('{$this->table_name}.index'); @@ -138,7 +138,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_edit_a_{$this->lang_name}_within_search_query() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->visitRoute('{$this->table_name}.index', ['q' => '123']); \$this->click('edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -169,7 +169,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_required() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name empty \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields(['name' => ''])); @@ -180,7 +180,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name 70 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -193,7 +193,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // description 256 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -206,8 +206,8 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_delete_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); - factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); + {$this->model_name}::factory()->create(); \$this->visitRoute('{$this->table_name}.index', ['action' => 'edit', 'id' => \${$this->single_model_var_name}->id]); \$this->click('del-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -244,7 +244,7 @@ class Manage{$this->model_name}Test extends TestCase namespace Tests; -use App\User; +use App\Models\User; use Laravel\BrowserKitTesting\TestCase as BaseTestCase; abstract class {$baseTestClass} extends BaseTestCase @@ -263,7 +263,7 @@ abstract class {$baseTestClass} extends BaseTestCase protected function createUser() { - return factory(User::class)->create(); + return User::factory()->create(); } } "; @@ -294,7 +294,7 @@ class Manage{$this->model_name}Test extends TestCase /** @test */ public function user_can_see_{$this->lang_name}_list_in_{$this->lang_name}_index_page() { - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); \$this->loginAsUser(); \$this->visitRoute('{$this->table_name}.index'); @@ -369,7 +369,7 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_edit_a_{$this->lang_name}_within_search_query() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); \$this->visitRoute('{$this->table_name}.index', ['q' => '123']); \$this->click('edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id); @@ -400,7 +400,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_required() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name empty \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields(['name' => ''])); @@ -411,7 +411,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_name_update_is_not_more_than_60_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // name 70 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -424,7 +424,7 @@ class Manage{$this->model_name}Test extends TestCase public function validate_{$this->lang_name}_description_update_is_not_more_than_255_characters() { \$this->loginAsUser(); - \${$this->lang_name} = factory({$this->model_name}::class)->create(['name' => 'Testing 123']); + \${$this->lang_name} = {$this->model_name}::factory()->create(['name' => 'Testing 123']); // description 256 characters \$this->patch(route('{$this->table_name}.update', \${$this->lang_name}), \$this->getEditFields([ @@ -437,8 +437,8 @@ class Manage{$this->model_name}Test extends TestCase public function user_can_delete_a_{$this->lang_name}() { \$this->loginAsUser(); - \${$this->single_model_var_name} = factory({$this->model_name}::class)->create(); - factory({$this->model_name}::class)->create(); + \${$this->single_model_var_name} = {$this->model_name}::factory()->create(); + {$this->model_name}::factory()->create(); \$this->visitRoute('{$this->table_name}.index', ['action' => 'edit', 'id' => \${$this->single_model_var_name}->id]); \$this->click('del-{$this->lang_name}-'.\${$this->single_model_var_name}->id); diff --git a/tests/TestCase.php b/tests/TestCase.php index 7723a4d..75d8ed7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,7 +20,7 @@ abstract class TestCase extends BaseTestCase parent::setUp(); $this->model_name = 'MemberType'; - $this->full_model_name = 'App\\'.$this->model_name; + $this->full_model_name = 'App\\Models\\'.$this->model_name; $this->plural_model_name = Str::plural($this->model_name); $this->table_name = Str::snake($this->plural_model_name); $this->lang_name = Str::snake($this->model_name); @@ -41,6 +41,7 @@ abstract class TestCase extends BaseTestCase { $this->removeFileOrDir(app_path($this->model_name.'.php')); $this->removeFileOrDir(app_path('Entities')); + $this->removeFileOrDir(app_path('Models')); $this->removeFileOrDir(app_path('Http')); $this->removeFileOrDir(database_path('migrations')); $this->removeFileOrDir(database_path('factories'));