Browse Source

Merge pull request #26 from nafiesl/laravel_8_crud_generator

Laravel 8 CRUD Generator (Prepare version 2.x)
tags/2.0.0 2.0.0
Nafies Luthfi 5 years ago
committed by GitHub
parent
commit
6a62523697
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .travis.yml
  2. 8
      composer.json
  3. 5014
      composer.lock
  4. 2
      src/GeneratorCommand.php
  5. 4
      src/stubs/controllers/full-formrequests.stub
  6. 4
      src/stubs/controllers/full.stub
  7. 29
      src/stubs/database/factories/model-factory.stub
  8. 3
      src/stubs/models/model-formfield.stub
  9. 3
      src/stubs/models/model.stub
  10. 2
      src/stubs/routes/api.stub
  11. 2
      src/stubs/routes/web.stub
  12. 4
      src/stubs/testcases/browserkit-base-class.stub
  13. 14
      src/stubs/testcases/feature/api.stub
  14. 14
      src/stubs/testcases/feature/full.stub
  15. 14
      src/stubs/testcases/feature/simple.stub
  16. 4
      src/stubs/testcases/unit/model-formfield.stub
  17. 6
      src/stubs/testcases/unit/model-policy.stub
  18. 4
      src/stubs/testcases/unit/model.stub
  19. 8
      tests/CommandOptions/FullCrudBs3OptionsTest.php
  20. 8
      tests/CommandOptions/FullCrudFormRequestOptionsTest.php
  21. 8
      tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php
  22. 23
      tests/CommandOptions/FullCrudFormfieldOptionsTest.php
  23. 6
      tests/CommandOptions/SimpleCrudBs3OptionsTest.php
  24. 6
      tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php
  25. 6
      tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php
  26. 26
      tests/CommandOptions/TestsOnlyOptionsTest.php
  27. 59
      tests/CrudApiMakeCommandTest.php
  28. 94
      tests/CrudMakeClassPropertiesTest.php
  29. 46
      tests/CrudMakeCommandTest.php
  30. 60
      tests/CrudSimpleMakeCommandTest.php
  31. 28
      tests/Generators/Api/ApiFeatureTestGeneratorTest.php
  32. 4
      tests/Generators/Api/RouteApiGeneratorTest.php
  33. 50
      tests/Generators/FeatureTestGeneratorTest.php
  34. 8
      tests/Generators/FullControllerGeneratorTest.php
  35. 33
      tests/Generators/ModelFactoryGeneratorTest.php
  36. 16
      tests/Generators/ModelGeneratorTest.php
  37. 18
      tests/Generators/ModelPolicyTestGeneratorTest.php
  38. 21
      tests/Generators/ModelTestGeneratorTest.php
  39. 4
      tests/Generators/RouteWebGeneratorTest.php
  40. 36
      tests/Generators/Simple/FeatureTestGeneratorTest.php
  41. 4
      tests/Generators/Simple/ViewsGeneratorTest.php
  42. 4
      tests/Generators/ViewsGeneratorTest.php
  43. 3
      tests/TestCase.php

2
.travis.yml

@ -1,7 +1,7 @@
language: php
php:
- 7.1.8
- 7.3
before_script:
- travis_retry composer install --prefer-source --no-interaction

8
composer.json

@ -20,12 +20,12 @@
}
},
"require": {
"php": ">=7.0.0",
"illuminate/support": "5.8.*||^6.0||^7.0||^8.0",
"laravel/browser-kit-testing": "^5.0||^6.0"
"php": "^7.3|^8.0",
"illuminate/support": "^8.0",
"laravel/browser-kit-testing": "^6.0"
},
"require-dev": {
"orchestra/testbench": "~3.0"
"orchestra/testbench": "^6.0"
},
"extra": {
"laravel": {

5014
composer.lock
File diff suppressed because it is too large
View File

2
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';
}
/**

4
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)

4
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)

29
src/stubs/database/factories/model-factory.stub

@ -1,16 +1,23 @@
<?php
use App\User;
namespace Database\Factories;
use App\Models\User;
use fullMstr;
use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factories\Factory;
$factory->define(Master::class, function (Faker $faker) {
class MasterFactory extends Factory
{
protected $model = Master::class;
return [
'name' => $faker->word,
'description' => $faker->sentence,
'creator_id' => function () {
return factory(User::class)->create()->id;
},
];
});
public function definition()
{
return [
'name' => $this->faker->word,
'description' => $this->faker->sentence,
'creator_id' => function () {
return User::factory()->create()->id;
},
];
}
}

3
src/stubs/models/model-formfield.stub

@ -3,10 +3,13 @@
namespace mstrNmspc;
use App\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Master extends Model
{
use HasFactory;
protected $fillable = ['name', 'description', 'creator_id'];
public function getNameLinkAttribute()

3
src/stubs/models/model.stub

@ -3,10 +3,13 @@
namespace mstrNmspc;
use App\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Master extends Model
{
use HasFactory;
protected $fillable = ['name', 'description', 'creator_id'];
public function getNameLinkAttribute()

2
src/stubs/routes/api.stub

@ -2,4 +2,4 @@
/*
* Masters Endpoints
*/
Route::middleware('auth:api')->resource('masters', 'Api\MasterController')->names('api.masters');
Route::middleware('auth:api')->resource('masters', App\Http\Controllers\Api\MasterController::class)->names('api.masters');

2
src/stubs/routes/web.stub

@ -2,4 +2,4 @@
/*
* Masters Routes
*/
Route::resource('masters', 'MasterController');
Route::resource('masters', App\Http\Controllers\MasterController::class);

4
src/stubs/testcases/browserkit-base-class.stub

@ -2,7 +2,7 @@
namespace Tests;
use App\User;
use App\Models\User;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
abstract class BrowserKitTest extends BaseTestCase
@ -21,6 +21,6 @@ abstract class BrowserKitTest extends BaseTestCase
protected function createUser()
{
return factory(User::class)->create();
return User::factory()->create();
}
}

14
src/stubs/testcases/feature/api.stub

@ -14,7 +14,7 @@ class ManageMasterTest extends TestCase
public function user_can_see_master_list_in_master_index_page()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->getJson(route('api.masters.index'), [
'Authorization' => 'Bearer '.$user->api_token
@ -111,7 +111,7 @@ class ManageMasterTest extends TestCase
public function user_can_get_a_master_detail()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create(['name' => 'Testing 123']);
$singleMstr = Master::factory()->create(['name' => 'Testing 123']);
$this->getJson(route('api.masters.show', $singleMstr), [
'Authorization' => 'Bearer '.$user->api_token
@ -124,7 +124,7 @@ class ManageMasterTest extends TestCase
public function user_can_update_a_master()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create(['name' => 'Testing 123']);
$singleMstr = Master::factory()->create(['name' => 'Testing 123']);
$this->patchJson(route('api.masters.update', $singleMstr), [
'name' => 'Master 1 name',
@ -158,7 +158,7 @@ class ManageMasterTest extends TestCase
public function validate_master_name_update_is_required()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
// name empty
$requestBody = $this->getEditFields(['name' => '']);
@ -176,7 +176,7 @@ class ManageMasterTest extends TestCase
public function validate_master_name_update_is_not_more_than_60_characters()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
// name 70 characters
$requestBody = $this->getEditFields(['name' => str_repeat('Test Title', 7)]);
@ -194,7 +194,7 @@ class ManageMasterTest extends TestCase
public function validate_master_description_update_is_not_more_than_255_characters()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create(['name' => 'Testing 123']);
$singleMstr = Master::factory()->create(['name' => 'Testing 123']);
// description 256 characters
$requestBody = $this->getEditFields(['description' => str_repeat('Long description', 16)]);
@ -212,7 +212,7 @@ class ManageMasterTest extends TestCase
public function user_can_delete_a_master()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->deleteJson(route('api.masters.destroy', $singleMstr), [
'master_id' => $singleMstr->id,

14
src/stubs/testcases/feature/full.stub

@ -13,7 +13,7 @@ class ManageMasterTest extends TestCase
/** @test */
public function user_can_see_master_list_in_master_index_page()
{
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->loginAsUser();
$this->visitRoute('masters.index');
@ -90,7 +90,7 @@ class ManageMasterTest extends TestCase
public function user_can_edit_a_master()
{
$this->loginAsUser();
$singleMstr = factory(Master::class)->create(['name' => 'Testing 123']);
$singleMstr = Master::factory()->create(['name' => 'Testing 123']);
$this->visitRoute('masters.show', $singleMstr);
$this->click('edit-master-'.$singleMstr->id);
@ -109,7 +109,7 @@ class ManageMasterTest extends TestCase
public function validate_master_name_update_is_required()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
$master = Master::factory()->create(['name' => 'Testing 123']);
// name empty
$this->patch(route('masters.update', $master), $this->getEditFields(['name' => '']));
@ -120,7 +120,7 @@ class ManageMasterTest extends TestCase
public function validate_master_name_update_is_not_more_than_60_characters()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
$master = Master::factory()->create(['name' => 'Testing 123']);
// name 70 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
@ -133,7 +133,7 @@ class ManageMasterTest extends TestCase
public function validate_master_description_update_is_not_more_than_255_characters()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
$master = Master::factory()->create(['name' => 'Testing 123']);
// description 256 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
@ -146,8 +146,8 @@ class ManageMasterTest extends TestCase
public function user_can_delete_a_master()
{
$this->loginAsUser();
$singleMstr = factory(Master::class)->create();
factory(Master::class)->create();
$singleMstr = Master::factory()->create();
Master::factory()->create();
$this->visitRoute('masters.edit', $singleMstr);
$this->click('del-master-'.$singleMstr->id);

14
src/stubs/testcases/feature/simple.stub

@ -13,7 +13,7 @@ class ManageMasterTest extends TestCase
/** @test */
public function user_can_see_master_list_in_master_index_page()
{
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->loginAsUser();
$this->visitRoute('masters.index');
@ -88,7 +88,7 @@ class ManageMasterTest extends TestCase
public function user_can_edit_a_master_within_search_query()
{
$this->loginAsUser();
$singleMstr = factory(Master::class)->create(['name' => 'Testing 123']);
$singleMstr = Master::factory()->create(['name' => 'Testing 123']);
$this->visitRoute('masters.index', ['q' => '123']);
$this->click('edit-master-'.$singleMstr->id);
@ -119,7 +119,7 @@ class ManageMasterTest extends TestCase
public function validate_master_name_update_is_required()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
$master = Master::factory()->create(['name' => 'Testing 123']);
// name empty
$this->patch(route('masters.update', $master), $this->getEditFields(['name' => '']));
@ -130,7 +130,7 @@ class ManageMasterTest extends TestCase
public function validate_master_name_update_is_not_more_than_60_characters()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
$master = Master::factory()->create(['name' => 'Testing 123']);
// name 70 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
@ -143,7 +143,7 @@ class ManageMasterTest extends TestCase
public function validate_master_description_update_is_not_more_than_255_characters()
{
$this->loginAsUser();
$master = factory(Master::class)->create(['name' => 'Testing 123']);
$master = Master::factory()->create(['name' => 'Testing 123']);
// description 256 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
@ -156,8 +156,8 @@ class ManageMasterTest extends TestCase
public function user_can_delete_a_master()
{
$this->loginAsUser();
$singleMstr = factory(Master::class)->create();
factory(Master::class)->create();
$singleMstr = Master::factory()->create();
Master::factory()->create();
$this->visitRoute('masters.index', ['action' => 'edit', 'id' => $singleMstr->id]);
$this->click('del-master-'.$singleMstr->id);

4
src/stubs/testcases/unit/model-formfield.stub

@ -14,7 +14,7 @@ class MasterTest extends TestCase
/** @test */
public function a_master_has_name_link_attribute()
{
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->assertEquals(
link_to_route('masters.show', $singleMstr->name, [$singleMstr], [
@ -29,7 +29,7 @@ class MasterTest extends TestCase
/** @test */
public function a_master_has_belongs_to_creator_relation()
{
$singleMstr = factory(Master::class)->make();
$singleMstr = Master::factory()->make();
$this->assertInstanceOf(User::class, $singleMstr->creator);
$this->assertEquals($singleMstr->creator_id, $singleMstr->creator->id);

6
src/stubs/testcases/unit/model-policy.stub

@ -21,7 +21,7 @@ class MasterPolicyTest extends TestCase
public function user_can_view_master()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->assertTrue($user->can('view', $singleMstr));
}
@ -29,7 +29,7 @@ class MasterPolicyTest extends TestCase
public function user_can_update_master()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->assertTrue($user->can('update', $singleMstr));
}
@ -37,7 +37,7 @@ class MasterPolicyTest extends TestCase
public function user_can_delete_master()
{
$user = $this->createUser();
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$this->assertTrue($user->can('delete', $singleMstr));
}
}

4
src/stubs/testcases/unit/model.stub

@ -14,7 +14,7 @@ class MasterTest extends TestCase
/** @test */
public function a_master_has_name_link_attribute()
{
$singleMstr = factory(Master::class)->create();
$singleMstr = Master::factory()->create();
$title = __('app.show_detail_title', [
'name' => $singleMstr->name, 'type' => __('master.master'),
@ -30,7 +30,7 @@ class MasterTest extends TestCase
/** @test */
public function a_master_has_belongs_to_creator_relation()
{
$singleMstr = factory(Master::class)->make();
$singleMstr = Master::factory()->make();
$this->assertInstanceOf(User::class, $singleMstr->creator);
$this->assertEquals($singleMstr->creator_id, $singleMstr->creator->id);

8
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
{
@ -12,9 +12,9 @@ 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('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');
@ -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"));

8
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
{
@ -12,9 +12,9 @@ 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('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"));
@ -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"));

8
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
{
@ -12,9 +12,9 @@ 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('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');
@ -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"));

23
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,9 +12,9 @@ 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('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');
@ -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,19 +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\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 = "<?php
namespace App;
namespace App\Models;
use App\User;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class {$this->model_name} extends Model
{
use HasFactory;
protected \$fillable = ['name', 'description', 'creator_id'];
public function getNameLinkAttribute()
@ -280,6 +284,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");
@ -300,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}], [
@ -315,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);

6
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
{
@ -12,9 +12,9 @@ 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('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');

6
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
{
@ -12,9 +12,9 @@ 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('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');

6
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
{
@ -12,9 +12,9 @@ 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('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');

26
tests/CommandOptions/TestsOnlyOptionsTest.php

@ -2,10 +2,10 @@
namespace Tests\CommandOptions;
use Tests\TestCase;
use Illuminate\Contracts\Console\Kernel;
use Tests\TestCase;
class TestOnlyOptionsTest extends TestCase
class TestsOnlyOptionsTest extends TestCase
{
/** @test */
public function it_can_generate_only_tests_files()
@ -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);
}
}

59
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"));
@ -36,25 +36,24 @@ 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->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"));

94
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'));
}
}

46
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"));
@ -39,11 +39,11 @@ 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);
$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"));

60
tests/CrudSimpleMakeCommandTest.php

@ -4,16 +4,16 @@ namespace Tests;
use Illuminate\Contracts\Console\Kernel;
class CrudSimpleCommandTest extends TestCase
class CrudSimpleMakeCommandTest extends TestCase
{
/** @test */
public function it_can_generate_simple_crud_files()
{
$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('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,57 +37,57 @@ 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->assertFileNotExists(app_path("Http/Controllers/{$this->model_name}Controller.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');
$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"));

28
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,

4
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));
}

50
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);

8
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)

33
tests/Generators/ModelFactoryGeneratorTest.php

@ -15,20 +15,27 @@ class ModelFactoryGeneratorTest extends TestCase
$this->assertFileExists($modelFactoryPath);
$modelFactoryContent = "<?php
use App\User;
namespace Database\Factories;
use App\Models\User;
use {$this->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));
}

16
tests/Generators/ModelGeneratorTest.php

@ -9,19 +9,23 @@ 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 = "<?php
namespace App;
namespace App\Models;
use App\User;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class {$this->model_name} extends Model
{
use HasFactory;
protected \$fillable = ['name', 'description', 'creator_id'];
public function getNameLinkAttribute()
@ -49,6 +53,7 @@ class {$this->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');
@ -57,11 +62,14 @@ 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;
class Category extends Model
{
use HasFactory;
protected \$fillable = ['name', 'description', 'creator_id'];
public function getNameLinkAttribute()

18
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}));
}
}

21
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);

4
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));
}

36
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);

4
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)

4
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)

3
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'));

Loading…
Cancel
Save