Browse Source

Fix some deprecated assertions

pull/26/head
Nafies Luthfi 5 years ago
parent
commit
537478e2d3
  1. 2
      src/GeneratorCommand.php
  2. 4
      tests/CommandOptions/FullCrudBs3OptionsTest.php
  3. 4
      tests/CommandOptions/FullCrudFormRequestOptionsTest.php
  4. 4
      tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php
  5. 8
      tests/CommandOptions/FullCrudFormfieldOptionsTest.php
  6. 2
      tests/CommandOptions/SimpleCrudBs3OptionsTest.php
  7. 2
      tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php
  8. 2
      tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php
  9. 22
      tests/CommandOptions/TestsOnlyOptionsTest.php
  10. 57
      tests/CrudApiMakeCommandTest.php
  11. 44
      tests/CrudMakeCommandTest.php
  12. 52
      tests/CrudSimpleMakeCommandTest.php
  13. 10
      tests/Generators/ModelGeneratorTest.php
  14. 4
      tests/Generators/Simple/ViewsGeneratorTest.php
  15. 4
      tests/Generators/ViewsGeneratorTest.php

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
tests/CommandOptions/FullCrudBs3OptionsTest.php

@ -12,7 +12,7 @@ class FullCrudBs3OptionsTest extends TestCase
{
$this->artisan('make:crud', ['name' => $this->model_name, '--bs3' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
@ -23,7 +23,7 @@ class FullCrudBs3OptionsTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));

4
tests/CommandOptions/FullCrudFormRequestOptionsTest.php

@ -12,7 +12,7 @@ class FullCrudFormRequestOptionsTest extends TestCase
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true, '--form-requests' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
@ -25,7 +25,7 @@ class FullCrudFormRequestOptionsTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));

4
tests/CommandOptions/FullCrudFormfieldBs3OptionsTest.php

@ -12,7 +12,7 @@ class FullCrudFormfieldBs3OptionsTest extends TestCase
{
$this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true, '--bs3' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
@ -23,7 +23,7 @@ class FullCrudFormfieldBs3OptionsTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));

8
tests/CommandOptions/FullCrudFormfieldOptionsTest.php

@ -2,8 +2,8 @@
namespace Tests\CommandOptions;
use Tests\TestCase;
use Illuminate\Contracts\Console\Kernel;
use Tests\TestCase;
class FullCrudFormfieldOptionsTest extends TestCase
{
@ -12,7 +12,7 @@ class FullCrudFormfieldOptionsTest extends TestCase
{
$this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
@ -23,7 +23,7 @@ class FullCrudFormfieldOptionsTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
@ -243,6 +243,7 @@ class FullCrudFormfieldOptionsTest extends TestCase
/** @test */
public function it_creates_correct_model_class_with_link_to_route_helper()
{
config(['auth.providers.users.model' => 'App\User']);
$this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
$modelPath = app_path($this->model_name.'.php');
@ -280,6 +281,7 @@ class {$this->model_name} extends Model
/** @test */
public function it_creates_correct_unit_test_class_with_link_to_route_helper()
{
config(['auth.providers.users.model' => 'App\User']);
$this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
$uniTestPath = base_path("tests/Unit/Models/{$this->model_name}Test.php");

2
tests/CommandOptions/SimpleCrudBs3OptionsTest.php

@ -12,7 +12,7 @@ class SimpleCrudBs3OptionsTest extends TestCase
{
$this->artisan('make:crud-simple', ['name' => $this->model_name, '--bs3' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));

2
tests/CommandOptions/SimpleCrudFormfieldBs3OptionsTest.php

@ -12,7 +12,7 @@ class SimpleCrudFormfieldBs3OptionsTest extends TestCase
{
$this->artisan('make:crud-simple', ['name' => $this->model_name, '--formfield' => true, '--bs3' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));

2
tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php

@ -12,7 +12,7 @@ class SimpleCrudFormfieldOptionsTest extends TestCase
{
$this->artisan('make:crud-simple', ['name' => $this->model_name, '--formfield' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));

22
tests/CommandOptions/TestsOnlyOptionsTest.php

@ -17,28 +17,28 @@ class TestOnlyOptionsTest extends TestCase
$output = app(Kernel::class)->output();
$this->assertNotContains("{$this->model_name} model already exists.", $output);
$this->assertStringNotContainsString("{$this->model_name} model already exists.", $output);
$this->assertFileNotExists(app_path($this->model_name.'.php'));
$this->assertFileNotExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
$this->assertFileDoesNotExist(app_path($this->model_name.'.php'));
$this->assertFileDoesNotExist(app_path("Http/Controllers/{$this->model_name}Controller.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
$this->assertFileNotExists($migrationFilePath);
$this->assertFileDoesNotExist($migrationFilePath);
$this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(base_path("routes/web.php"));
$this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileDoesNotExist(base_path("routes/web.php"));
$this->assertFileDoesNotExist(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileDoesNotExist(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php"));
$this->assertContains('Test files generated successfully!', $output);
$this->assertStringContainsString('Test files generated successfully!', $output);
}
}

57
tests/CrudApiMakeCommandTest.php

@ -11,16 +11,16 @@ class CrudApiMakeCommandTest extends TestCase
{
$this->artisan('make:crud-api', ['name' => $this->model_name, '--no-interaction' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path('Models/'.$this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/Api/{$this->model_name}Controller.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
$this->assertFileExists($migrationFilePath);
$this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
@ -39,22 +39,21 @@ class CrudApiMakeCommandTest extends TestCase
$this->artisan('make:model', ['name' => $this->model_name, '--no-interaction' => true]);
$this->artisan('make:crud-api', ['name' => $this->model_name, '--no-interaction' => true]);
$this->assertContains("We will use existing {$this->model_name} model.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertStringContainsString("We will use existing {$this->model_name} model.", app(Kernel::class)->output());
$this->assertFileExists(app_path('Models/'.$this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/Api/{$this->model_name}Controller.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
$this->assertFileNotExists($migrationFilePath);
$this->assertFileDoesNotExist($migrationFilePath);
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(base_path("routes/web.php"));
$this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileNotExists(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
$this->assertFileNotExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php"));
$this->assertFileDoesNotExist(base_path("routes/web.php"));
$this->assertFileDoesNotExist(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileDoesNotExist(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php"));
$this->assertFileExists(base_path("tests/Feature/Api/Manage{$this->model_name}Test.php"));
}
@ -64,24 +63,24 @@ class CrudApiMakeCommandTest extends TestCase
$this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:crud-api', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->assertContains("We will use existing Problem model.", app(Kernel::class)->output());
$this->assertStringContainsString("We will use existing Problem model.", app(Kernel::class)->output());
$this->assertFileExists(app_path('Entities/Projects/Problem.php'));
$this->assertFileExists(app_path("Http/Controllers/Api/ProblemController.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_problems_table.php');
$this->assertFileNotExists($migrationFilePath);
$this->assertFileDoesNotExist($migrationFilePath);
$this->assertFileNotExists(resource_path("views/problems/index.blade.php"));
$this->assertFileNotExists(resource_path("views/problems/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(app_path("Policies/ProblemPolicy.php"));
$this->assertFileNotExists(database_path("factories/ProblemFactory.php"));
$this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php"));
$this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php"));
$this->assertFileDoesNotExist(app_path("Policies/ProblemPolicy.php"));
$this->assertFileDoesNotExist(database_path("factories/ProblemFactory.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Models/ProblemTest.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Policies/ProblemPolicyTest.php"));
$this->assertFileExists(base_path("tests/Feature/Api/ManageProblemTest.php"));
$this->removeFileOrDir(app_path('Entities/Projects'));
@ -101,7 +100,7 @@ class CrudApiMakeCommandTest extends TestCase
$this->artisan('make:crud-api', ['name' => $inputName, '--no-interaction' => true]);
$this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php'));
$this->assertFileExists(app_path("Http/Controllers/Api/{$modelName}Controller.php"));
@ -109,8 +108,8 @@ class CrudApiMakeCommandTest extends TestCase
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php');
$this->assertFileExists($migrationFilePath);
$this->assertFileNotExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));
@ -135,7 +134,7 @@ class CrudApiMakeCommandTest extends TestCase
$this->artisan('make:crud-api', ['name' => $inputName, '--parent' => $parentName, '--no-interaction' => true]);
$this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php'));
$this->assertFileExists(app_path("Http/Controllers/Api/{$parentName}/{$modelName}Controller.php"));
@ -143,8 +142,8 @@ class CrudApiMakeCommandTest extends TestCase
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$tableName.'_table.php');
$this->assertFileExists($migrationFilePath);
$this->assertFileNotExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));

44
tests/CrudMakeCommandTest.php

@ -11,9 +11,9 @@ class CrudMakeCommandTest extends TestCase
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path('Models/'.$this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
@ -22,7 +22,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
@ -43,7 +43,7 @@ class CrudMakeCommandTest extends TestCase
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true])
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', true);
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path('Models/'.$this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
@ -52,7 +52,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
@ -69,30 +69,30 @@ class CrudMakeCommandTest extends TestCase
public function it_cannot_generate_crud_files_if_namespaced_model_exists()
{
$this->mockConsoleOutput = true;
$this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:model', ['name' => 'App/Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:crud', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true])
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', false)
->expectsOutput('Problem model already exists.');
$this->assertFileExists(app_path('Entities/Projects/Problem.php'));
$this->assertFileNotExists(app_path("Http/Controllers/ProblemsController.php"));
$this->assertFileDoesNotExist(app_path("Http/Controllers/ProblemsController.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_problems_table.php');
$this->assertFileNotExists($migrationFilePath);
$this->assertFileDoesNotExist($migrationFilePath);
$this->assertFileNotExists(resource_path("views/problems/index.blade.php"));
$this->assertFileNotExists(resource_path("views/problems/create.blade.php"));
$this->assertFileNotExists(resource_path("views/problems/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/problems/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/create.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/edit.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(app_path("Policies/ProblemPolicy.php"));
$this->assertFileNotExists(database_path("factories/ProblemFactory.php"));
$this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php"));
$this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php"));
$this->assertFileNotExists(base_path("tests/Feature/ManageProblemTest.php"));
$this->assertFileDoesNotExist(app_path("Policies/ProblemPolicy.php"));
$this->assertFileDoesNotExist(database_path("factories/ProblemFactory.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Models/ProblemTest.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Policies/ProblemPolicyTest.php"));
$this->assertFileDoesNotExist(base_path("tests/Feature/ManageProblemTest.php"));
$this->removeFileOrDir(app_path('Entities/Projects'));
$this->removeFileOrDir(resource_path('views/problems'));
@ -111,7 +111,7 @@ class CrudMakeCommandTest extends TestCase
$this->artisan('make:crud', ['name' => $inputName, '--no-interaction' => true]);
$this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$modelName}Controller.php"));
@ -122,7 +122,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));
@ -147,7 +147,7 @@ class CrudMakeCommandTest extends TestCase
$this->artisan('make:crud', ['name' => $inputName, '--parent' => $parentName, '--no-interaction' => true]);
$this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$modelName}Controller.php"));
@ -158,7 +158,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/create.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/edit.blade.php"));
$this->assertFileNotExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$tableName}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));

52
tests/CrudSimpleMakeCommandTest.php

@ -11,7 +11,7 @@ class CrudSimpleCommandTest extends TestCase
{
$this->artisan('make:crud-simple', ['name' => $this->model_name, '--no-interaction' => true]);
$this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$this->model_name} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
@ -43,51 +43,51 @@ class CrudSimpleCommandTest extends TestCase
->expectsOutput("{$this->model_name} model already exists.");
$this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileNotExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
$this->assertFileDoesNotExist(app_path("Http/Controllers/{$this->model_name}Controller.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
$this->assertFileNotExists($migrationFilePath);
$this->assertFileDoesNotExist($migrationFilePath);
$this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/{$this->table_name}/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(base_path("routes/web.php"));
$this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileNotExists(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
$this->assertFileNotExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php"));
$this->assertFileNotExists(base_path("tests/Feature/Manage{$this->model_name}Test.php"));
$this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileDoesNotExist(base_path("routes/web.php"));
$this->assertFileDoesNotExist(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileDoesNotExist(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php"));
$this->assertFileDoesNotExist(base_path("tests/Feature/Manage{$this->model_name}Test.php"));
}
/** @test */
public function it_cannot_generate_crud_files_if_namespaced_model_exists()
{
$this->mockConsoleOutput = true;
$this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:model', ['name' => 'App/Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:crud-simple', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true])
->expectsQuestion('Model file exists, are you sure to generate CRUD files?', false)
->expectsOutput("Problem model already exists.");
$this->assertFileExists(app_path('Entities/Projects/Problem.php'));
$this->assertFileNotExists(app_path("Http/Controllers/ProblemsController.php"));
$this->assertFileDoesNotExist(app_path("Http/Controllers/ProblemsController.php"));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_problems_table.php');
$this->assertFileNotExists($migrationFilePath);
$this->assertFileDoesNotExist($migrationFilePath);
$this->assertFileNotExists(resource_path("views/problems/index.blade.php"));
$this->assertFileNotExists(resource_path("views/problems/forms.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/index.blade.php"));
$this->assertFileDoesNotExist(resource_path("views/problems/forms.blade.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileDoesNotExist(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(app_path("Policies/ProblemPolicy.php"));
$this->assertFileNotExists(database_path("factories/ProblemFactory.php"));
$this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php"));
$this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php"));
$this->assertFileNotExists(base_path("tests/Feature/ManageProblemTest.php"));
$this->assertFileDoesNotExist(app_path("Policies/ProblemPolicy.php"));
$this->assertFileDoesNotExist(database_path("factories/ProblemFactory.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Models/ProblemTest.php"));
$this->assertFileDoesNotExist(base_path("tests/Unit/Policies/ProblemPolicyTest.php"));
$this->assertFileDoesNotExist(base_path("tests/Feature/ManageProblemTest.php"));
$this->removeFileOrDir(app_path('Entities/Projects'));
$this->removeFileOrDir(resource_path('views/problems'));
@ -106,7 +106,7 @@ class CrudSimpleCommandTest extends TestCase
$this->artisan('make:crud-simple', ['name' => $inputName, '--no-interaction' => true]);
$this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$modelName}Controller.php"));
@ -140,7 +140,7 @@ class CrudSimpleCommandTest extends TestCase
$this->artisan('make:crud-simple', ['name' => $inputName, '--parent' => $parentName, '--no-interaction' => true]);
$this->assertNotContains("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertStringNotContainsString("{$modelName} model already exists.", app(Kernel::class)->output());
$this->assertFileExists(app_path($modelPath.'/'.$modelName.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$parentName}/{$modelName}Controller.php"));

10
tests/Generators/ModelGeneratorTest.php

@ -15,13 +15,16 @@ class ModelGeneratorTest extends TestCase
$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()
@ -58,10 +61,13 @@ class {$this->model_name} extends Model
namespace App\Entities\References;
use App\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use HasFactory;
protected \$fillable = ['name', 'description', 'creator_id'];
public function getNameLinkAttribute()

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)

Loading…
Cancel
Save