diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4037851 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +* text=auto + +screenshots export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +phpunit.xml export-ignore +readme.md export-ignore +tests export-ignore \ No newline at end of file diff --git a/composer.json b/composer.json index c8007f1..e9e5670 100644 --- a/composer.json +++ b/composer.json @@ -33,5 +33,8 @@ "Luthfi\\CrudGenerator\\ServiceProvider" ] } + }, + "scripts": { + "test": "vendor/bin/phpunit" } } diff --git a/readme.md b/readme.md index a0c5062..1730796 100644 --- a/readme.md +++ b/readme.md @@ -6,22 +6,33 @@ An artisan `make:crud` command to create a simple CRUD feature on your Laravel 5 > **Development in progress** ## About this package -With this package installed on local environment, we can use (e.g.) `php artisan make:crud Item` command to generate some files : -- **App\Item.php** eloquent model -- **ItemsController.php** in `app/Http/Controllers` directory -- **create_items_table.php** migration file -- **index.blade.php** view file in `resources/views/items` directory -- **forms.blade.php** view file in `resources/views/items` directory -- **ManageItemsTest.php** feature test class in `tests/Feature` directory -- **ItemTest.php** unit test class in `tests/Unit/Models` directory - -The model will only have 2 pre-definded attributes or columns : `name` and `description` on each model and database table. +With this package installed on local environment, we can use (e.g.) `php artisan make:crud Vehicle` command to generate some files : +- `App\Vehicle.php` eloquent model +- `xxx_create_vehicles_table.php` migration file +- `VehiclesController.php` +- `index.blade.php` and `forms.blade.php` view file in `resources/views/vehicles` directory +- `resources/lang/vehicle.php` lang file +- `VehicleFactory.php` model factory file +- `VehiclePolicy.php` model policy file in `app/Policies` directory +- `ManageVehiclesTest.php` feature test class in `tests/Feature` directory +- `VehicleTest.php` unit test class in `tests/Unit/Models` directory +- `VehiclePolicyTest.php` unit test class in `tests/Unit/Policies` directory + +It will update some file : +- Update `routes/web.php` to add `vehicles` resource route +- Update `app/providers/AuthServiceProvider.php` to add Vehicle model Policy class in `$policies` property + +It will also create this file **if it not exists** : +- `resources/lang/app.php` lang file if it not exists +- `tests/BrowserKitTest.php` base Feature TestCase class if it not exists + +The **Model and table** will only have 2 pre-definded attributes or columns : `name` and `description` on each generated model and database table. ## Attention -- This package still in development -- Use this package on new Laravel project for simulation. -- It will creates the **Model** class file, don't use it to generate files for existing **Model** class. - You need a `resources/views/layouts/app.blade.php` view file, simply create one with `php artisan make:auth` command. +- Use this package on new Laravel project for simulation. +- It will creates the **Model** class file, ~don't use it to generate files for existing Model~ it cancel the command if the **Model already exists**. +- This package still in development ## How to install This package has not been submitted to packagist, so we can use github repo as additional repository. To have the additional repository, we do some configiration on `composer.json` file, add this : @@ -54,18 +65,23 @@ $ php artisan We will find the `make:crud` command, it will `Create simple Laravel CRUD files of given model name`. ```bash -$ php artisan make:crud Item - -Item resource route generated on routes/web.php. -Item model generated. -Item table migration generated. -ItemsController generated. -Item view files generated. -item lang files generated. -item model factory generated. +$ php artisan make:crud Vehicle + +Vehicle resource route generated on routes/web.php. +Vehicle model generated. +Vehicle table migration generated. +VehiclesController generated. +Vehicle index view file generated. +Vehicle form view file generated. +lang/app.php generated. +vehicle lang files generated. +Vehicle model factory generated. +Vehicle model policy generated. +AuthServiceProvider class has been updated. BrowserKitTest generated. -ManageItemsTest generated. -ItemTest (model) generated. +ManageVehiclesTest generated. +VehicleTest (model) generated. +VehiclePolicyTest (model policy) generated. CRUD files generated successfully! ``` @@ -73,13 +89,16 @@ Create mysql database, set your database credential on `.env` file. Then : ```bash $ php artisan migrate +$ php artisan serve ``` -Visit your application in new resource route : `http://127.0.0.1:8000/items` +Visit your application in new resource route : `http://127.0.0.1:8000/vehicles` + +![Generated CRUD page by Simple CRUD Generator](screenshots/simple-crud-generator-01.jpg) -The CRUD function should work. +### Let's try the generated testing suite -Next, to use the generated testing classes, we can set the database environment using in-memory database SQLite. Open `phpunit.xml`. Add two lines below on the `env` : +Next, to use the generated testing classes, we can set the database environment using *in-memory* database SQLite. Open `phpunit.xml`. Add two lines below on the `env` : ```xml @@ -92,7 +111,7 @@ Next, to use the generated testing classes, we can set the database environment ``` -Try out the generated testing classes via terminal. +Then run PHPUnit ```bash $ vendor/bin/phpunit @@ -100,6 +119,8 @@ $ vendor/bin/phpunit All tests should be passed. +![Generated Testing Suite on Simple CRUD Generator](screenshots/simple-crud-generator-02.jpg) + ## License This package is open-sourced software licensed under the [MIT license](LICENSE). diff --git a/screenshots/simple-crud-generator-01.jpg b/screenshots/simple-crud-generator-01.jpg new file mode 100644 index 0000000..66f2fe1 Binary files /dev/null and b/screenshots/simple-crud-generator-01.jpg differ diff --git a/screenshots/simple-crud-generator-02.jpg b/screenshots/simple-crud-generator-02.jpg new file mode 100644 index 0000000..70f7e59 Binary files /dev/null and b/screenshots/simple-crud-generator-02.jpg differ