diff --git a/.gitignore b/.gitignore index e09a5f7..fa1293d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ .editorconfig .DS_Store /package -composer.lock \ No newline at end of file +composer.lock +.phpunit.result.cache \ No newline at end of file diff --git a/app/Commands/Create.php b/app/Commands/Create.php index e6fb404..d5937f6 100644 --- a/app/Commands/Create.php +++ b/app/Commands/Create.php @@ -13,7 +13,7 @@ class Create extends Command * * @var string */ - protected $signature = 'new {name?} {vendor?} {author_name?} {author_email?} {path?}'; + protected $signature = 'new {name?} {vendor?} {author_name?} {author_email?} {keywords?} {path?} '; /** * The description of the command. @@ -133,7 +133,11 @@ protected function setPackageName() */ protected function setKeywords() { - $keywords = $this->ask('Enter keywords (comma separated)'); + $keywords = $this->argument('keywords'); + if (!$keywords) { + $keywords = $this->ask('Enter keywords (comma separated)'); + } + if ($keywords) { $keywords = str_replace(', ', ',', $keywords); } diff --git a/app/Commands/Crud/CrudMigrationCreator.php b/app/Commands/Crud/CrudMigrationCreator.php index ba87dd6..803bb27 100644 --- a/app/Commands/Crud/CrudMigrationCreator.php +++ b/app/Commands/Crud/CrudMigrationCreator.php @@ -2,6 +2,7 @@ namespace App\Commands\Crud; +use Illuminate\Filesystem\Filesystem; use App\Commands\Helpers\PackageDetail; use Illuminate\Database\Migrations\MigrationCreator as RealMigrationCreator; @@ -9,8 +10,9 @@ class CrudMigrationCreator extends RealMigrationCreator { use PackageDetail; - public function __construct() + public function __construct(Filesystem $files) { + $this->files = $files; } /** diff --git a/app/Commands/Helpers/MakeFile.php b/app/Commands/Helpers/MakeFile.php index c589c49..6c443cc 100644 --- a/app/Commands/Helpers/MakeFile.php +++ b/app/Commands/Helpers/MakeFile.php @@ -87,14 +87,15 @@ protected function replaceContent() { $vendor = cache()->get('vendor'); $packageName = cache()->get('package_name'); - $keywords = cache()->get('keywords'); + $keywords = cache()->get('keywords'); - if(!$keywords) $composerKeywords = ''; - else { + if (!$keywords) { + $composerKeywords = ''; + } else { $composerKeywords = PHP_EOL; - $keywords = explode(',', $keywords); + $keywords = explode(',', $keywords); foreach ($keywords as $keyword) { - $composerKeywords .= "\t\t".'"' . $keyword .'",' . PHP_EOL; + $composerKeywords .= "\t\t" . '"' . $keyword . '",' . PHP_EOL; } $composerKeywords .= "\t"; //format keywords array diff --git a/app/Commands/Helpers/PackageDetail.php b/app/Commands/Helpers/PackageDetail.php index 11530ab..bee6f82 100644 --- a/app/Commands/Helpers/PackageDetail.php +++ b/app/Commands/Helpers/PackageDetail.php @@ -23,12 +23,12 @@ public function namespaceFromComposer() protected function getVendor() { - return str_before($this->namespaceFromComposer(), '\\'); + return Str::before($this->namespaceFromComposer(), '\\'); } protected function getPackageName() { - return str_replace('\\', '', Str::after($this->namespaceFromComposer(), '\\')); + return Str::replace('\\', '', Str::after($this->namespaceFromComposer(), '\\')); } /** diff --git a/tests/Feature/CrudMakeTest.php b/tests/Feature/CrudMakeTest.php new file mode 100644 index 0000000..c8de158 --- /dev/null +++ b/tests/Feature/CrudMakeTest.php @@ -0,0 +1,45 @@ +isFileExists('crud/Test.json'); + } + + public function test_it_can_create_a_crud_for_a_json_file() + { + Artisan::call('crud:json Test'); + Artisan::call('crud:make crud/Test.json'); + $this->isFileExists('src/Test.php'); + $this->isFileExists('src/database/factories/TestFactory.php'); + $this->isFileExists('src/Http/controllers/TestController.php'); + $this->isFileExists('tests/Feature/TestTest.php'); + $this->isFileExists('tests/Unit/TestTest.php'); + } + + public function isFileExists($filename) + { + return $this->assertFileExists(base_path() . '/package/TestApp/' . $filename); + } +}