diff --git a/README.md b/README.md index 82d8b76..2cb6ce0 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,38 @@ Note: You should have configured database for this operation. php artisan crud:generate Posts --fields="title#string; content#text; category#select#options=technology,tips,health" --view-path=admin --controller-namespace=Admin --route-group=admin ``` +#### Crud fields from a JSON file: + +```json +{ + "fields": [ + { + "name": "title", + "type": "string" + }, + { + "name": "content", + "type": "text" + }, + { + "name": "category", + "type": "select", + "options": ["technology", "tips", "health"] + } + ] +} +``` + +``` +php artisan crud:generate Posts --fields_from_file="/path/to/fields.json" --view-path=admin --controller-namespace=Admin --route-group=admin +``` + Options: | Option | Description | | --- | --- | | `--fields` | Fields name for the form & migration. e.g. ```--fields="title#string; content#text; category#select#options=technology,tips,health; user_id#integer#unsigned"``` | +| `--fields_from_file` | Fields from a JSON file. e.g. ```--fields_from_file="/path/to/fields.json"``` | | `--route` | Include Crud route to routes.php? yes or no | | `--pk` | The name of the primary key | | `--view-path` | The name of the view path | diff --git a/composer.json b/composer.json index 16c8425..76a6038 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ }, "require-dev": { "mockery/mockery": "^0.9.6", - "phpunit/phpunit": "^5.6", - "orchestra/testbench": "3.3.x-dev" + "phpunit/phpunit": "^5.7", + "orchestra/testbench": "^3.3" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/tests/CrudGeneratorTest.php b/tests/CrudGeneratorTest.php index 8b0643d..f71140d 100644 --- a/tests/CrudGeneratorTest.php +++ b/tests/CrudGeneratorTest.php @@ -9,8 +9,6 @@ public function testCrudGenerateCommand() // '--fields' => "title#string; content#text; category#select#options=technology,tips,health", // ]); // $this->assertContains('Controller already exists!', $this->consoleOutput()); - - $this->assertFileNotExists('/path/to/file.php'); } public function testControllerGenerateCommand() @@ -22,6 +20,8 @@ public function testControllerGenerateCommand() ]); $this->assertContains('Controller created successfully.', $this->consoleOutput()); + + $this->assertFileExists(app_path('Http/Controllers') . '/CustomersController.php'); } public function testModelGenerateCommand() @@ -32,6 +32,8 @@ public function testModelGenerateCommand() ]); $this->assertContains('Model created successfully.', $this->consoleOutput()); + + $this->assertFileExists(app_path() . '/Customer.php'); } public function testMigrationGenerateCommand() @@ -52,5 +54,7 @@ public function testViewGenerateCommand() ]); $this->assertContains('View created successfully.', $this->consoleOutput()); + + $this->assertDirectoryExists(config('view.paths')[0] . '/customers'); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index eb0b2b9..849af5a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,5 +1,4 @@