Compare commits

...

10 Commits
master ... 1.2

Author SHA1 Message Date
Nafies Luthfi 2074cb9832 Use replace string helpers with Str class 6 years ago
Nafies Luthfi 5784e5eb34 Revert travis php and update phpunit command 6 years ago
Nafies Luthfi f9ed1175c5 Update travis php version 6 years ago
Nafies Luthfi 94ffb33a21 Add laravel 6.0 support 6 years ago
Nafies Luthfi 3d75b52530 Improve test cases 7 years ago
Nafies Luthfi 386f92e0ad Update BaseGenerator docblock 7 years ago
Nafies Luthfi 5031ef9ff3 Remove withoutMockingConsoleOutput method call 7 years ago
Nafies Luthfi c57a455b39 Update composer.lock for php 7.0 version 7 years ago
Nafies Luthfi 67e5e36ad4 Add withoutMockingConsoleOutput method call 7 years ago
Nafies Luthfi 7501e48a6d Change testbench version 7 years ago
  1. 3
      .gitignore
  2. 2
      .travis.yml
  3. 4
      composer.json
  4. 3862
      composer.lock
  5. 11
      src/GeneratorCommand.php
  6. 5
      src/Generators/BaseGenerator.php
  7. 4
      src/Generators/LangFileGenerator.php
  8. 7
      tests/CrudApiMakeCommandTest.php
  9. 5
      tests/CrudMakeCommandTest.php
  10. 5
      tests/CrudSimpleMakeCommandTest.php
  11. 5
      tests/Generators/LangGeneratorTest.php
  12. 9
      tests/TestCase.php

3
.gitignore

@ -1,2 +1 @@
/vendor
composer.lock
/vendor

2
.travis.yml

@ -7,4 +7,4 @@ before_script:
- travis_retry composer install --prefer-source --no-interaction
script:
- phpunit --bootstrap=vendor/autoload.php tests
- vendor/bin/phpunit --bootstrap=vendor/autoload.php tests

4
composer.json

@ -21,11 +21,11 @@
},
"require": {
"php": ">=7.0.0",
"illuminate/support": "5.5.* || 5.6.* || 5.7.* || 5.8.*",
"illuminate/support": "5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0",
"laravel/browser-kit-testing": "2.0.x-dev || ^4.0 || ^5.0"
},
"require-dev": {
"orchestra/testbench": "~3.0"
"orchestra/testbench": ">=3.0 <3.8"
},
"extra": {
"laravel": {

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

11
src/GeneratorCommand.php

@ -2,6 +2,7 @@
namespace Luthfi\CrudGenerator;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Console\DetectsApplicationNamespace;
@ -61,7 +62,7 @@ class GeneratorCommand extends Command
{
$modelName = is_null($modelName) ? $this->argument('name') : $modelName;
$model_name = ucfirst(class_basename($modelName));
$plural_model_name = str_plural($model_name);
$plural_model_name = Str::plural($model_name);
$modelPath = $this->getModelPath($modelName);
$modelNamespace = $this->getModelNamespace($modelPath);
@ -70,10 +71,10 @@ class GeneratorCommand extends Command
'full_model_name' => $modelNamespace.'\\'.$model_name,
'plural_model_name' => $plural_model_name,
'model_name' => $model_name,
'table_name' => snake_case($plural_model_name),
'lang_name' => snake_case($model_name),
'collection_model_var_name' => camel_case($plural_model_name),
'single_model_var_name' => camel_case($model_name),
'table_name' => Str::snake($plural_model_name),
'lang_name' => Str::snake($model_name),
'collection_model_var_name' => Str::camel($plural_model_name),
'single_model_var_name' => Str::camel($model_name),
'model_path' => $modelPath,
];
}

5
src/Generators/BaseGenerator.php

@ -121,6 +121,11 @@ abstract class BaseGenerator implements GeneratorContract
return $this->files->get(__DIR__.'/../stubs/'.$stubName.'.stub');
}
/**
* Check whether we generating API CRUD or not.
*
* @return bool
*/
protected function isForApi()
{
return $this->command->getName() == 'make:crud-api';

4
src/Generators/LangFileGenerator.php

@ -2,6 +2,8 @@
namespace Luthfi\CrudGenerator\Generators;
use Illuminate\Support\Str;
/**
* Lang File Generator Class
*/
@ -35,7 +37,7 @@ class LangFileGenerator extends BaseGenerator
$stub = $this->files->get(__DIR__.'/../stubs/resources/lang/en/master.stub');
}
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->modelNames['model_name'])));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->modelNames['model_name'])));
$properLangFileContent = str_replace(
$this->modelNames['model_name'],

7
tests/CrudApiMakeCommandTest.php

@ -29,6 +29,7 @@ class CrudApiMakeCommandTest extends TestCase
$this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileExists(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/Api/Manage{$this->model_name}Test.php"));
}
@ -53,11 +54,12 @@ class CrudApiMakeCommandTest extends TestCase
$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->assertFileExists(base_path("tests/Feature/Api/Manage{$this->model_name}Test.php"));
}
/** @test */
public function it_cannot_generate_crud_files_if_namespaced_model_exists()
public function it_not_generate_api_crud_files_if_namespaced_model_exists()
{
$this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
$this->artisan('make:crud-api', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]);
@ -79,6 +81,7 @@ class CrudApiMakeCommandTest extends TestCase
$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->assertFileExists(base_path("tests/Feature/Api/ManageProblemTest.php"));
$this->removeFileOrDir(app_path('Entities/Projects'));
@ -115,6 +118,7 @@ class CrudApiMakeCommandTest extends TestCase
$this->assertFileExists(app_path("Policies/{$modelName}Policy.php"));
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php"));
$this->assertFileExists(base_path("tests/Feature/Api/Manage{$modelName}Test.php"));
}
@ -147,6 +151,7 @@ class CrudApiMakeCommandTest extends TestCase
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php"));
$this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php"));
$this->assertFileExists(base_path("tests/Feature/Api/Manage{$modelName}Test.php"));
}

5
tests/CrudMakeCommandTest.php

@ -31,6 +31,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileExists(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"));
}
@ -60,6 +61,7 @@ class CrudMakeCommandTest extends TestCase
$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"));
}
@ -88,6 +90,7 @@ class CrudMakeCommandTest extends TestCase
$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->removeFileOrDir(app_path('Entities/Projects'));
@ -126,6 +129,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(app_path("Policies/{$modelName}Policy.php"));
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php"));
}
@ -160,6 +164,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php"));
$this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php"));
}

5
tests/CrudSimpleMakeCommandTest.php

@ -29,6 +29,7 @@ class CrudSimpleCommandTest extends TestCase
$this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
$this->assertFileExists(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"));
}
@ -56,6 +57,7 @@ class CrudSimpleCommandTest extends TestCase
$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"));
}
@ -82,6 +84,7 @@ class CrudSimpleCommandTest extends TestCase
$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->removeFileOrDir(app_path('Entities/Projects'));
@ -118,6 +121,7 @@ class CrudSimpleCommandTest extends TestCase
$this->assertFileExists(app_path("Policies/{$modelName}Policy.php"));
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php"));
}
@ -150,6 +154,7 @@ class CrudSimpleCommandTest extends TestCase
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php"));
$this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php"));
}

5
tests/Generators/LangGeneratorTest.php

@ -3,6 +3,7 @@
namespace Tests\Generators;
use Tests\TestCase;
use Illuminate\Support\Str;
class LangGeneratorTest extends TestCase
{
@ -13,7 +14,7 @@ class LangGeneratorTest extends TestCase
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->model_name)));
$this->assertFileExists($langPath);
$langFileContent = "<?php
@ -60,7 +61,7 @@ return [
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->model_name)));
$this->assertFileExists($langPath);
$langFileContent = "<?php

9
tests/TestCase.php

@ -2,6 +2,7 @@
namespace Tests;
use Illuminate\Support\Str;
use Orchestra\Testbench\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
@ -21,10 +22,10 @@ abstract class TestCase extends BaseTestCase
$this->full_model_name = 'App\\'.$this->model_name;
$this->plural_model_name = str_plural($this->model_name);
$this->table_name = snake_case($this->plural_model_name);
$this->lang_name = snake_case($this->model_name);
$this->collection_model_var_name = camel_case($this->plural_model_name);
$this->single_model_var_name = camel_case($this->model_name);
$this->table_name = Str::snake($this->plural_model_name);
$this->lang_name = Str::snake($this->model_name);
$this->collection_model_var_name = Str::camel($this->plural_model_name);
$this->single_model_var_name = Str::camel($this->model_name);
}
public function tearDown()

Loading…
Cancel
Save