Compare commits

...

59 Commits

Author SHA1 Message Date
Arthur
f1debe575e
Package name update
Package name update
2020-04-06 20:12:04 +03:00
Arthur
2efa3595a5
Update README.md 2020-04-06 20:10:23 +03:00
Arthur
c46846d978
Update dependencies
Update dependencies to work with Lumen v.6
2020-04-06 20:06:58 +03:00
Amine Ben hammou
8d804e09eb
Merge pull request #50 from davidporos92/hotfix/migration-generator
Delete old migration file if exists when creating a new one
2018-06-09 05:30:26 +00:00
Amine Ben hammou
a6008f4a40 Merge pull request #48 from AfzalH/master
Some fixes for latest lumen. Also added customized response for NOT_FOUND and NO_CONTENT response
2017-10-23 00:12:29 +02:00
Pörös Dávid
86493ab228 delete old migration file
refs #44
2017-10-21 01:19:28 +02:00
Afzal Hossain
50c3e78483 Better control over not_found and no_content response 2017-10-20 19:04:20 +06:00
Afzal Hossain
ee03649641 Single quote around model to avoid IDE warning 2017-10-20 19:02:37 +06:00
Afzal Hossain
8ee7bbe6b7 $app->get() no longer works. Replaced. 2017-10-20 19:01:22 +06:00
Amine Ben hammou
73e470ec15 Merge pull request #40 from josiahdahl/laravel-routes
Enable Creating Laravel Style Routes
2017-08-09 00:57:18 +02:00
Josiah Dahl
c5218a1fd8 Merge branch 'master' into laravel-routes 2017-08-08 14:10:20 -07:00
Amine Ben hammou
014c617cc5 Merge pull request #39 from josiahdahl/sequential-model-filenames
Sequential Filenames with Resources Command
2017-08-08 21:52:03 +02:00
Josiah Dahl
8b6e2db315 Added database for testing 2017-08-07 12:28:22 -07:00
Josiah Dahl
a2cb5e4437 Add database creation for testing 2017-08-07 12:23:08 -07:00
Josiah Dahl
9a82b80cb1 fix test bug 2017-08-07 12:12:39 -07:00
Josiah Dahl
56f0d9c0a9 Ensure commands work and tests pass 2017-08-07 11:51:53 -07:00
Josiah Dahl
573d55c9b2 updated README 2017-08-07 11:51:43 -07:00
Josiah Dahl
a951151697 Finalize testing 2017-08-07 11:02:36 -07:00
Josiah Dahl
5e2c21855e Tests are failing only for the new route options 2017-08-06 23:06:04 -07:00
Josiah Dahl
2817f3591b Add resources data 2017-08-06 23:01:36 -07:00
Josiah Dahl
a2cf22d426 Added Laravel Routes
- New template
- Command updates
2017-08-06 20:54:39 -07:00
Josiah Dahl
6e00a91eea Fixed string padding 2017-08-06 15:56:01 -07:00
Josiah Dahl
afa5bf1f0c Pad the model index to 3 characters 2017-08-06 09:44:50 -07:00
Josiah Dahl
982dee15fc Possible codeception updates 2017-08-06 09:37:25 -07:00
Josiah Dahl
434e7f6b2c Testing Resources Command
Finialized testing the changes to the resources command.
2017-08-06 09:36:57 -07:00
Amine Ben hammou
dafa7f2f22 Release 1.3.3 2017-05-08 02:22:45 +02:00
Amine Ben hammou
874e793594 Merge pull request #36 from StephaneBour/master
fix path option for wn:ressources
2017-05-08 02:15:09 +02:00
Stéphane
7d42825426
rollback: remove path (I just understood that it was only for the model...) 2017-05-07 21:58:49 +02:00
Stéphane
7f1b5407ee
chore: composer update 2017-05-07 21:28:18 +02:00
Stéphane
cc39d720c4
fix: rules not support space
replace space by comma (i think the bug is same for #33)
2017-05-07 21:27:58 +02:00
Stéphane
9ab561df2f
fix: change version of codeception 2017-05-07 20:24:40 +02:00
Stéphane
5662a5d4bb
fix: add path if option is passed 2017-05-07 20:00:32 +02:00
Stéphane
b22b59ab5d
perf: detect if codecept exist 2017-05-07 19:40:18 +02:00
Amine Ben hammou
5cf6f6ed9c Model softDeletes trait fixed 2017-02-04 21:55:44 +00:00
Amine Ben hammou
8e57d36894 bug fixed: soft deletes missing in the model 2017-01-28 14:35:11 +00:00
Amine Ben hammou
5ad49aa58a release 1.3.1 2017-01-20 19:20:55 +00:00
Amine Ben hammou
057199cb8b fixed the duplicate column for the foriegn key bug 2017-01-20 19:01:25 +00:00
Amine Ben hammou
27dc508bca code quality tools added 2017-01-18 19:45:27 +00:00
Amine Ben hammou
de26849f18 editorconfig added 2017-01-18 19:36:03 +00:00
Amine Ben hammou
9ba5b5f7fe updates README 2017-01-18 18:40:11 +00:00
Amine Ben hammou
cfe5b2f69b updating wn:resources to follow changes on wn:resource 2017-01-18 18:21:40 +00:00
Amine Ben hammou
482cc3f8c4 preparing release 1.3.0 2017-01-18 15:55:18 +00:00
Amine Ben hammou
55fcf27362 add support for lumen 5.3.x 2017-01-18 14:18:58 +00:00
Amine Ben hammou
93856362b7 refering the package locally from lumen-test 2017-01-18 13:33:35 +00:00
Amine Ben hammou
6e7d3fbf95 Merge pull request #19 from webNeat/bugfixes
Preparing Version 1.2.0
2017-01-12 17:02:38 +01:00
Amine Ben hammou
a9c12e9fa0 - Tests fixed.
- Bug fixed: [Undefined index: factory](https://github.com/webNeat/lumen-generators/issues/14)
- Feature added: [Check if file already exists before generating it](https://github.com/webNeat/lumen-generators/issues/11)
- Feature added: [Support for additional columns like nullableTimestamps() and softDeletes() in migrations](https://github.com/webNeat/lumen-generators/issues/12)
- Feature added: [Specifying namespace for `wn:resource` and `wn:resources`](https://github.com/webNeat/lumen-generators/issues/18)
2017-01-12 16:50:02 +01:00
Amine Ben hammou
17bc595db9 Fixing the failing build 2016-12-29 20:06:29 +01:00
Hernawan Fa'iz Abdillah
942b8fefb4 Change tab to space
Using PSR-2 standard.
2016-03-30 14:42:16 +07:00
Hernawan Fa'iz Abdillah
b2510a01e4 Fix to PSR-2 style 2016-03-30 14:28:44 +07:00
Amine Ben hammou
c0daa0c97b wn:resource: foreign keys are added automatically to model, migration and factory 2016-02-25 22:47:13 +01:00
Amine Ben hammou
3eae8983c9 pivot seeder called from wn:resources 2016-02-23 20:57:23 +01:00
Amine Ben hammou
6094a546fc adding missing app folder 2016-02-23 20:34:04 +01:00
abenhammou
024b2e33d0 added missing env file 2016-02-22 12:12:16 +01:00
abenhammou
33d7a151ae added missing database folder 2016-02-22 11:55:12 +01:00
Amine Ben hammou
b6d47df699 pivot table seeder generator added and tested 2016-02-22 00:38:41 +01:00
Amine Ben hammou
5f8f2f2888 untracking lumen-test files 2016-02-21 22:11:01 +01:00
Amine Ben hammou
d149e7532e fix seeder generator test 2016-02-20 00:04:30 +01:00
Amine Ben hammou
5605377f86 Seeder generator added 2016-02-19 23:31:29 +01:00
Amine Ben hammou
8af58ea50a Factory generator activated 2016-02-19 21:17:03 +01:00
76 changed files with 2074 additions and 2325 deletions

14
.editorconfig Normal file
View File

@ -0,0 +1,14 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
[*.php]
charset = utf-8
indent_size = 4
[*.{json,yml}]
charset = utf-8
indent_size = 2

7
.gitignore vendored
View File

@ -4,5 +4,8 @@
tests/_output/* tests/_output/*
lumen-test/app/ lumen-test/app
lumen-test/database/ lumen-test/database
lumen-test/tests/tmp
.idea

View File

@ -4,11 +4,12 @@ php:
- 5.5 - 5.5
- 5.6 - 5.6
- 7.0 - 7.0
- 7.1
- hhvm - hhvm
matrix: matrix:
allow_failures: allow_failures:
- php: 7.0 - php: hhvm
sudo: false sudo: false

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2014 Amine Ben hammou <webneat@gmail.com> Copyright (c) 2015 Amine Ben hammou <webneat@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

149
README.md
View File

@ -1,9 +1,11 @@
# Lumen generators # Lumen generators
[![Build Status](https://travis-ci.org/webNeat/lumen-generators.svg?branch=master)](https://travis-ci.org/webNeat/lumen-generators) [![Build Status](https://travis-ci.org/webNeat/lumen-generators.svg?branch=master)](https://travis-ci.org/webNeat/lumen-generators)
[![License](https://poser.pugx.org/laravel/framework/license.svg)](http://opensource.org/licenses/MIT) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/webNeat/lumen-generators/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/webNeat/lumen-generators/?branch=master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/838624c3-208d-4ba5-84aa-3afc76b093bb/mini.png)](https://insight.sensiolabs.com/projects/838624c3-208d-4ba5-84aa-3afc76b093bb)
[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://github.com/webNeat/lumen-generators/blob/master/LICENSE)
A collection of generators for [Lumen](http://lumen.laravel.com) and [Laravel 5](http://laravel.com/). A collection of generators for [Lumen](http://lumen.laravel.com) and [Laravel 6](http://laravel.com/).
## Contents ## Contents
@ -79,7 +81,7 @@ wn:route Generates RESTful routes.
To generate a RESTful resource for your application (model, migration, controller and RESTful routes), you simply need to run one single command. For example: To generate a RESTful resource for your application (model, migration, controller and RESTful routes), you simply need to run one single command. For example:
``` ```
php artisan wn:resource task "name;string;required;fillable project_id;integer:unsigned;numeric;fillable,key due;date;;date" --belongs-to=project php artisan wn:resource task "name;string;required;fillable project_id;integer:unsigned;numeric;fillable,key due;date;;date" --add=timestamps --belongs-to=project
``` ```
will generate these files: will generate these files:
@ -257,7 +259,7 @@ More then that, you can generate multiple resources with only one command ! [Cli
The `wn:model` command is used to generate a model class based on Eloquent. It has the following syntax: The `wn:model` command is used to generate a model class based on Eloquent. It has the following syntax:
``` ```
wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--path=...] wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--timestamps=false] [--path=...] [--soft-deletes=true] [--force=true]
``` ```
- **name**: the name of the model. - **name**: the name of the model.
@ -357,12 +359,22 @@ gives:
]; ];
``` ```
- **--timestamps**: Enables timestamps on the model. Giving `--timestamps=false` will add `public $timestamps = false;` to the generated model. The default value is `true`.
- **--soft-deletes**: Adds `Illuminate\Database\Eloquent\SoftDeletes` trait to the model. This is disabled by default.
- **--force**: tells the generator to override the existing file. By default, if the model file already exists, it will not be overriden and the output will be something like:
```
TestingModel model already exists; use --force option to override it !
```
### Migration Generator ### Migration Generator
The `wn:migration` command is used to generate a migration to create a table with schema. It has the following syntax: The `wn:migration` command is used to generate a migration to create a table with schema. It has the following syntax:
``` ```
wn:migration table [--schema=...] [--keys=...] [--file=...] wn:migration table [--schema=...] [--add=...] [--keys=...] [--force=true] [--file=...]
``` ```
- **table**: the name of the table to create. - **table**: the name of the table to create.
@ -392,7 +404,7 @@ class CreateTasksMigration extends Migration
$table->decimal('amount', 5, 2)->after('size')->default(8); $table->decimal('amount', 5, 2)->after('size')->default(8);
$table->string('title')->nullable(); $table->string('title')->nullable();
// Constraints declaration // Constraints declaration
$table->timestamps();
}); });
} }
@ -403,6 +415,8 @@ class CreateTasksMigration extends Migration
} }
``` ```
- **--add**: Specifies additional columns like `timestamps`, `softDeletes`, `rememberToken` and `nullableTimestamps`.
- **--keys**: the foreign keys of the table following the syntax `field:column:table:on_delete:on_update ...`. The `column` is optional ("id" by default). The `table` is optional if the field follows the naming convention `singular_table_name_id`. `on_delete` and `on_update` are optional too. - **--keys**: the foreign keys of the table following the syntax `field:column:table:on_delete:on_update ...`. The `column` is optional ("id" by default). The `table` is optional if the field follows the naming convention `singular_table_name_id`. `on_delete` and `on_update` are optional too.
``` ```
@ -427,15 +441,17 @@ $table->foreign('user_id')
The `wn:pivot-table` command is used to generate a migration to create a pivot table between two models. It has the following syntax: The `wn:pivot-table` command is used to generate a migration to create a pivot table between two models. It has the following syntax:
``` ```
wn:pivot-table model1 model2 [--file=...] wn:pivot-table model1 model2 [--add=...] [--force=true] [--file=...]
``` ```
- **model1** and **model2**: names of the two models (or the two tables if the models don't follow the naming conventions) - **model1** and **model2**: names of the two models (or the two tables if the models don't follow the naming conventions)
- **--add**: Specifies additional columns like `timestamps`, `softDeletes`, `rememberToken` and `nullableTimestamps`.
- **--file**: The migration file name. By default the name follows the patern `date_time_create_table_name.php`. - **--file**: The migration file name. By default the name follows the patern `date_time_create_table_name.php`.
``` ```
php artisan wn:pivot-table Tag Project php artisan wn:pivot-table Tag Project --add=timestamps
``` ```
gives: gives:
@ -487,12 +503,16 @@ There are two commands for controllers. The first one is `wn:controller:rest-act
Note that the trait doesn't use the common used methods on Laravel (like index, store, ...) to avoid conflicts. Which enables you to use this trait with controllers you already have in your application. Note that the trait doesn't use the common used methods on Laravel (like index, store, ...) to avoid conflicts. Which enables you to use this trait with controllers you already have in your application.
The second command is `wn:controller` which actually generates the controller. The syntax of this command is `wn:controller model [--no-routes]`. The second command is `wn:controller` which actually generates the controller. The syntax of this command is `wn:controller model [--no-routes] [--force=true]`.
- **model**: Name of the model (with namespace if not `App`). - **model**: Name of the model (with namespace if not `App`).
- **--no-routes**: Since routes are generated by default for the controller, this option is used to tell the generator "do not generate routes !". - **--no-routes**: Since routes are generated by default for the controller, this option is used to tell the generator "do not generate routes !".
- **--force**: tells the generator to override the existing file.
- **--laravel**: create Laravel style routes
`php artisan wn:controller Task --no-routes` gives: `php artisan wn:controller Task --no-routes` gives:
@ -513,12 +533,17 @@ class TasksController extends Controller {
The `wn:route` command is used to generate RESTfull routes for a controller. It has the following syntax: The `wn:route` command is used to generate RESTfull routes for a controller. It has the following syntax:
`wn:route resource [--controller=...]` `wn:route resource [--controller=...] [--force=true]`
- **resource**: the resource name to use in the URLs. - **resource**: the resource name to use in the URLs.
- **--controller**: the corresponding controller. If missing it's deducted from the resource name. - **--controller**: the corresponding controller. If missing it's deducted from the resource name.
- **--force**: tells the generator to override the existing file.
- **--laravel**: create Laravel style routes
`php artisan wn:route project-type` adds the following routes: `php artisan wn:route project-type` adds the following routes:
```php ```php
@ -529,9 +554,20 @@ $app->put('project-type/{id}', 'ProjectTypesController@put');
$app->delete('project-type/{id}', 'ProjectTypesController@remove'); $app->delete('project-type/{id}', 'ProjectTypesController@remove');
``` ```
`php artisan wn:route project-type --laravel` adds the following routes:
```php
Route::get('project-type', 'ProjectTypesController@all');
Route::get('project-type/{id}', 'ProjectTypesController@get');
Route::post('project-type', 'ProjectTypesController@add');
Route::put('project-type/{id}', 'ProjectTypesController@put');
Route::delete('project-type/{id}', 'ProjectTypesController@remove');
```
### Resource Generator ### Resource Generator
The `wn:resource` command makes it very easy to generate a RESTful resource. It generates a model, migration, controller and routes. The syntax is : `wn:resource name fields [--has-many=...] [--has-one=...] [--belongs-to=...] [--migration-file=...]` The `wn:resource` command makes it very easy to generate a RESTful resource. It generates a model, migration, controller and routes. The syntax is : `wn:resource name fields [--add=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--migration-file=...] [--path=...] [--force=true]`
- **name**: the name of the resource used in the URLs and to determine the model, table and controller names. - **name**: the name of the resource used in the URLs and to determine the model, table and controller names.
@ -551,22 +587,36 @@ The `wn:resource` command makes it very easy to generate a RESTful resource. It
- `key`: this field is a foreign key. - `key`: this field is a foreign key.
- **--add**: Specifies additional columns like `timestamps`, `softDeletes`, `rememberToken` and `nullableTimestamps` of the migration and if the list contains no timestamps, the model with contain `public $timestamps = false;`.
- **--has-one**, **--has-many** and **--belongs-to** are the same as for the `wn:model` command. - **--has-one**, **--has-many** and **--belongs-to** are the same as for the `wn:model` command.
- **--migration-file**: passed to the `wn:migration` as the `--file` option. - **--migration-file**: passed to the `wn:migration` as the `--file` option.
- **--path**: Defines where to store the model file as well as its namespace.
- **--force**: tells the generator to override the existing file.
- **--laravel**: create Laravel style routes
### Multiple Resources From File ### Multiple Resources From File
The `wn:resources` (note the "s" in "resources") command takes the generation process to an other level by parsing a file and generating multiple resources based on it. The syntax is The `wn:resources` (note the "s" in "resources") command takes the generation process to an other level by parsing a file and generating multiple resources based on it. The syntax is
``` ```
wn:resources filename wn:resources filename [--path=...] [--force=true]
``` ```
This generator is smart enough to add foreign keys automatically when finding a belongsTo relation. It also generates pivot tables for belongsToMany relations automatically. This generator is smart enough to add foreign keys automatically when finding a belongsTo relation. It also generates pivot tables for belongsToMany relations automatically.
The file given to the command should be a valid YAML file ( for the moment, support of other types like XML or JSON could be added in the future). An example is the following: The file given to the command should be a valid YAML file ( for the moment, support of other types like XML or JSON could be added in the future). An example is the following:
- **--path**: Defines where to store the model files as well as their namespace.
- **--laravel**: create Laravel style routes
```yaml ```yaml
--- ---
Store: Store:
@ -598,6 +648,7 @@ Product:
schema: 'decimal:5,2' # need quotes when using ',' schema: 'decimal:5,2' # need quotes when using ','
rules: numeric rules: numeric
tags: fillable tags: fillable
add: timestamps softDeletes
``` ```
## Testing ## Testing
@ -606,6 +657,64 @@ To test the generators, I included a fresh lumen installation under the folder `
## Development Notes ## Development Notes
- **Comming versions**
- **Seeder and Test generators**
- Requested Feature: [Custom Templates](https://github.com/webNeat/lumen-generators/issues/13)
- Requested Feature: [Fractal integration](https://github.com/webNeat/lumen-generators/issues/24)
- Requested Feature: [Add possibility to not run migrations when using `wn:resources`](https://github.com/webNeat/lumen-generators/issues/23)
- Documentation: [Adding examples](https://github.com/webNeat/lumen-generators/issues/20)
- **Version 1.3.3**
- Bug Fixed: [Rules issue when creating resources from YAML file](https://github.com/webNeat/lumen-generators/issues/30)
- **Version 1.3.2**
- Bug Fixed: [softDeletes not added to model](https://github.com/webNeat/lumen-generators/issues/25)
- **Version 1.3.1**
- Bug Fixed: [duplicate column for the foriegn key when using `wn:resources`](https://github.com/webNeat/lumen-generators/issues/22)
- **Version 1.3.0**
- Requested Feature: [Disabling timestamps](https://github.com/webNeat/lumen-generators/issues/15)
- Requested Feature: [Lumen 5.3 routes support](https://github.com/webNeat/lumen-generators/issues/21)
- **Version 1.2.0**
- Tests fixed.
- Bug fixed: [Undefined index: factory](https://github.com/webNeat/lumen-generators/issues/14)
- Feature added: [Check if file already exists before generating it](https://github.com/webNeat/lumen-generators/issues/11)
- Feature added: [Support for additional columns like nullableTimestamps() and softDeletes() in migrations](https://github.com/webNeat/lumen-generators/issues/12)
- Feature added: [Specifying namespace for `wn:resource` and `wn:resources`](https://github.com/webNeat/lumen-generators/issues/18)
- **Version 1.1.1**
- Pivot table generation from the `wn:resources` command bug fixed.
- **Version 1.1.0**
- Pivot table generator added.
- belongsToMany relationship added to model generator.
- Multiple resources generator adds foreign keys for belongsTo relationships automatically.
- Multiple resources generator adds pivot tables for belongsToMany relationships automatically.
- Generated migrations file names changed to be supported by `migrate` command.
- **Version 1.0.0** - **Version 1.0.0**
- Model Generator - Model Generator
@ -620,22 +729,6 @@ To test the generators, I included a fresh lumen installation under the folder `
- Multiple Resources From File - Multiple Resources From File
- **Version 1.1.0**
- Pivot table generator added.
- belongsToMany relationship added to model generator.
- Multiple resources generator adds foreign keys for belongsTo relationships automatically.
- Multiple resources generator adds pivot tables for belongsToMany relationships automatically.
- Generated migrations file names changed to be supported by `migrate` command.
- **Version 1.1.1**
- Pivot table generation from the `wn:resources` command bug fixed.
## Contributing ## Contributing
Pull requests are welcome :D Pull requests are welcome :D

View File

@ -1,5 +1,5 @@
{ {
"name": "wn/lumen-generators", "name": "zorgcc/lumen-generators",
"description": "A collection of generators for Lumen and Laravel 5.", "description": "A collection of generators for Lumen and Laravel 5.",
"keywords": ["lumen", "laravel", "rest", "api", "generators"], "keywords": ["lumen", "laravel", "rest", "api", "generators"],
"license": "MIT", "license": "MIT",
@ -10,9 +10,9 @@
} }
], ],
"require": { "require": {
"php": ">=5.5.0", "php": "^7.2",
"illuminate/console": "^5.1", "illuminate/console": "^5.1|^6",
"illuminate/filesystem": "^5.1", "illuminate/filesystem": "^5.1|^6",
"fzaninotto/faker": "^1.5" "fzaninotto/faker": "^1.5"
}, },
"autoload": { "autoload": {

1915
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,19 +2,19 @@ APP_ENV=local
APP_DEBUG=true APP_DEBUG=true
APP_KEY=SomeRandomKey!!! APP_KEY=SomeRandomKey!!!
APP_LOCALE=en # APP_LOCALE=en
APP_FALLBACK_LOCALE=en # APP_FALLBACK_LOCALE=en
DB_CONNECTION=mysql DB_CONNECTION=sqlite
DB_HOST=localhost # DB_HOST=localhost
DB_PORT=3306 # DB_PORT=3306
DB_DATABASE=homestead # DB_DATABASE=homestead
DB_USERNAME=homestead # DB_USERNAME=homestead
DB_PASSWORD=secret # DB_PASSWORD=secret
CACHE_DRIVER=memcached # CACHE_DRIVER=memcached
SESSION_DRIVER=memcached # SESSION_DRIVER=memcached
QUEUE_DRIVER=database # QUEUE_DRIVER=database
# MAIL_DRIVER=smtp # MAIL_DRIVER=smtp
# MAIL_HOST=mailtrap.io # MAIL_HOST=mailtrap.io

View File

@ -1,9 +1,11 @@
/vendor /vendor
.env .env
codecept.phar
tests/_output/* tests/_output/*
composer.lock composer.lock
tests/_output/*
codecept.phar
lumen-test/app
lumen-test/database

View File

@ -8,3 +8,4 @@ class Controller extends BaseController
{ {
// //
} }

View File

@ -2,7 +2,7 @@
require_once __DIR__.'/../vendor/autoload.php'; require_once __DIR__.'/../vendor/autoload.php';
// Dotenv::load(__DIR__.'/../'); Dotenv::load(__DIR__.'/../');
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

51
lumen-test/clean.sh Executable file
View File

@ -0,0 +1,51 @@
# models
rm app/*.php 2> /dev/null
# migrations
rm database/migrations/*.php 2> /dev/null
# routes
echo "<?php
\$app->get(\"/\", function () use (\$app) {
return \$app->welcome();
});" > app/Http/routes.php
echo "<?php
/*
|------------------------------------------
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|------------------------------------------
*/
" > routes/api.php
# Controllers
rm app/Http/Controllers/*.php 2> /dev/null
echo "<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController
{
//
}
" > app/Http/Controllers/Controller.php
# factories
echo "<?php
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
" > database/factories/ModelFactory.php
# database
rm database/database.sqlite 2> /dev/null
touch database/database.sqlite

View File

@ -5,9 +5,10 @@ paths:
data: tests/_data data: tests/_data
support: tests/_support support: tests/_support
envs: tests/_envs envs: tests/_envs
helpers: nil
settings: settings:
bootstrap: _bootstrap.php bootstrap: _bootstrap.php
colors: true colors: false
memory_limit: 1024M memory_limit: 1024M
extensions: extensions:
enabled: enabled:

View File

@ -13,12 +13,12 @@
"phpunit/phpunit": "~4.0", "phpunit/phpunit": "~4.0",
"fzaninotto/faker": "~1.0", "fzaninotto/faker": "~1.0",
"phpspec/phpspec": "2.0.0", "phpspec/phpspec": "2.0.0",
"codeception/codeception": "2.0.0", "codeception/codeception": "^2.2"
"wn/lumen-generators": "@dev"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/",
"Wn\\Generators\\": "../src/"
}, },
"classmap": [ "classmap": [
"database/" "database/"

View File

@ -1,15 +0,0 @@
<?php
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicExample()
{
$this->visit('/')
->see('Lumen.');
}
}

View File

@ -1,14 +0,0 @@
<?php
class TestCase extends Laravel\Lumen\Testing\TestCase
{
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
return require __DIR__.'/../bootstrap/app.php';
}
}

View File

@ -0,0 +1,26 @@
---
Author:
belongsTo: book
fields:
name:
schema: string
tags: fillable
Book:
belongsTo: librarys # Yes I know it's misspelled...
hasOne: author
fields:
title:
schema: string
tags: fillable
published:
schema: date
tags: fillable
Library:
hasMany: books
fields:
name:
schema: string
tags: fillable
address:
schema: string
tags: fillable

View File

@ -12,7 +12,7 @@
* @method void am($role) * @method void am($role)
* @method void lookForwardTo($achieveValue) * @method void lookForwardTo($achieveValue)
* @method void comment($description) * @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null) * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
* *
* @SuppressWarnings(PHPMD) * @SuppressWarnings(PHPMD)
*/ */

View File

@ -12,7 +12,7 @@
* @method void am($role) * @method void am($role)
* @method void lookForwardTo($achieveValue) * @method void lookForwardTo($achieveValue)
* @method void comment($description) * @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null) * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
* *
* @SuppressWarnings(PHPMD) * @SuppressWarnings(PHPMD)
*/ */

View File

@ -1,5 +1,6 @@
<?php <?php
namespace Helper; namespace Helper;
// here you can define custom actions // here you can define custom actions
// all public methods declared in helper class will be available in $I // all public methods declared in helper class will be available in $I

View File

@ -1,5 +1,6 @@
<?php <?php
namespace Helper; namespace Helper;
// here you can define custom actions // here you can define custom actions
// all public methods declared in helper class will be available in $I // all public methods declared in helper class will be available in $I

View File

@ -1,5 +1,6 @@
<?php <?php
namespace Helper; namespace Helper;
// here you can define custom actions // here you can define custom actions
// all public methods declared in helper class will be available in $I // all public methods declared in helper class will be available in $I

View File

@ -12,7 +12,7 @@
* @method void am($role) * @method void am($role)
* @method void lookForwardTo($achieveValue) * @method void lookForwardTo($achieveValue)
* @method void comment($description) * @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null) * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
* *
* @SuppressWarnings(PHPMD) * @SuppressWarnings(PHPMD)
*/ */

View File

@ -1,4 +1,4 @@
<?php //[STAMP] 90ca27738c5db3919bd1f5813987c735 <?php //[STAMP] d6606f78456705b0875c6b8343fc6a4a
namespace _generated; namespace _generated;
// This class was automatically generated by build task // This class was automatically generated by build task
@ -17,6 +17,22 @@ trait AcceptanceTesterActions
abstract protected function getScenario(); abstract protected function getScenario();
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@ -95,7 +111,7 @@ trait AcceptanceTesterActions
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
* * @param $regex
* Conditional Assertion: Test won't be stopped on fail * Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Cli::seeShellOutputMatches() * @see \Codeception\Module\Cli::seeShellOutputMatches()
*/ */
@ -105,7 +121,7 @@ trait AcceptanceTesterActions
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
* * @param $regex
* @see \Codeception\Module\Cli::seeShellOutputMatches() * @see \Codeception\Module\Cli::seeShellOutputMatches()
*/ */
public function seeShellOutputMatches($regex) { public function seeShellOutputMatches($regex) {
@ -113,13 +129,83 @@ trait AcceptanceTesterActions
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIs(0);
* ```
*
* @param $code
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Cli::seeResultCodeIs()
*/
public function canSeeResultCodeIs($code) {
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResultCodeIs', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIs(0);
* ```
*
* @param $code
* @see \Codeception\Module\Cli::seeResultCodeIs()
*/
public function seeResultCodeIs($code) {
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResultCodeIs', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIsNot(0);
* ```
*
* @param $code
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Cli::seeResultCodeIsNot()
*/
public function canSeeResultCodeIsNot($code) {
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResultCodeIsNot', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIsNot(0);
* ```
*
* @param $code
* @see \Codeception\Module\Cli::seeResultCodeIsNot()
*/
public function seeResultCodeIsNot($code) {
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResultCodeIsNot', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
* Enters a directory In local filesystem. * Enters a directory In local filesystem.
* Project root directory is used by default * Project root directory is used by default
* *
* @param $path * @param string $path
* @see \Codeception\Module\Filesystem::amInPath() * @see \Codeception\Module\Filesystem::amInPath()
*/ */
public function amInPath($path) { public function amInPath($path) {
@ -141,7 +227,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $filename * @param string $filename
* @see \Codeception\Module\Filesystem::openFile() * @see \Codeception\Module\Filesystem::openFile()
*/ */
public function openFile($filename) { public function openFile($filename) {
@ -160,7 +246,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $filename * @param string $filename
* @see \Codeception\Module\Filesystem::deleteFile() * @see \Codeception\Module\Filesystem::deleteFile()
*/ */
public function deleteFile($filename) { public function deleteFile($filename) {
@ -179,7 +265,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $dirname * @param string $dirname
* @see \Codeception\Module\Filesystem::deleteDir() * @see \Codeception\Module\Filesystem::deleteDir()
*/ */
public function deleteDir($dirname) { public function deleteDir($dirname) {
@ -198,8 +284,8 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $src * @param string $src
* @param $dst * @param string $dst
* @see \Codeception\Module\Filesystem::copyDir() * @see \Codeception\Module\Filesystem::copyDir()
*/ */
public function copyDir($src, $dst) { public function copyDir($src, $dst) {
@ -221,7 +307,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $text * @param string $text
* Conditional Assertion: Test won't be stopped on fail * Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeInThisFile() * @see \Codeception\Module\Filesystem::seeInThisFile()
*/ */
@ -242,7 +328,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $text * @param string $text
* @see \Codeception\Module\Filesystem::seeInThisFile() * @see \Codeception\Module\Filesystem::seeInThisFile()
*/ */
public function seeInThisFile($text) { public function seeInThisFile($text) {
@ -250,6 +336,74 @@ trait AcceptanceTesterActions
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks If opened file has the `number` of new lines.
*
* Usage:
*
* ``` php
* <?php
* $I->openFile('composer.json');
* $I->seeNumberNewLines(5);
* ?>
* ```
*
* @param int $number New lines
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeNumberNewLines()
*/
public function canSeeNumberNewLines($number) {
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberNewLines', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks If opened file has the `number` of new lines.
*
* Usage:
*
* ``` php
* <?php
* $I->openFile('composer.json');
* $I->seeNumberNewLines(5);
* ?>
* ```
*
* @param int $number New lines
* @see \Codeception\Module\Filesystem::seeNumberNewLines()
*/
public function seeNumberNewLines($number) {
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberNewLines', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that contents of currently opened file matches $regex
*
* @param string $regex
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
*/
public function canSeeThisFileMatches($regex) {
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeThisFileMatches', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that contents of currently opened file matches $regex
*
* @param string $regex
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
*/
public function seeThisFileMatches($regex) {
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeThisFileMatches', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@ -265,7 +419,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $text * @param string $text
* Conditional Assertion: Test won't be stopped on fail * Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeFileContentsEqual() * @see \Codeception\Module\Filesystem::seeFileContentsEqual()
*/ */
@ -287,7 +441,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $text * @param string $text
* @see \Codeception\Module\Filesystem::seeFileContentsEqual() * @see \Codeception\Module\Filesystem::seeFileContentsEqual()
*/ */
public function seeFileContentsEqual($text) { public function seeFileContentsEqual($text) {
@ -307,7 +461,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $text * @param string $text
* Conditional Assertion: Test won't be stopped on fail * Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::dontSeeInThisFile() * @see \Codeception\Module\Filesystem::dontSeeInThisFile()
*/ */
@ -326,7 +480,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $text * @param string $text
* @see \Codeception\Module\Filesystem::dontSeeInThisFile() * @see \Codeception\Module\Filesystem::dontSeeInThisFile()
*/ */
public function dontSeeInThisFile($text) { public function dontSeeInThisFile($text) {
@ -357,7 +511,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $filename * @param string $filename
* @param string $path * @param string $path
* Conditional Assertion: Test won't be stopped on fail * Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeFileFound() * @see \Codeception\Module\Filesystem::seeFileFound()
@ -377,7 +531,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $filename * @param string $filename
* @param string $path * @param string $path
* @see \Codeception\Module\Filesystem::seeFileFound() * @see \Codeception\Module\Filesystem::seeFileFound()
*/ */
@ -391,7 +545,7 @@ trait AcceptanceTesterActions
* *
* Checks if file does not exist in path * Checks if file does not exist in path
* *
* @param $filename * @param string $filename
* @param string $path * @param string $path
* Conditional Assertion: Test won't be stopped on fail * Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::dontSeeFileFound() * @see \Codeception\Module\Filesystem::dontSeeFileFound()
@ -404,7 +558,7 @@ trait AcceptanceTesterActions
* *
* Checks if file does not exist in path * Checks if file does not exist in path
* *
* @param $filename * @param string $filename
* @param string $path * @param string $path
* @see \Codeception\Module\Filesystem::dontSeeFileFound() * @see \Codeception\Module\Filesystem::dontSeeFileFound()
*/ */
@ -424,7 +578,7 @@ trait AcceptanceTesterActions
* ?> * ?>
* ``` * ```
* *
* @param $dirname * @param string $dirname
* @see \Codeception\Module\Filesystem::cleanDir() * @see \Codeception\Module\Filesystem::cleanDir()
*/ */
public function cleanDir($dirname) { public function cleanDir($dirname) {
@ -437,8 +591,8 @@ trait AcceptanceTesterActions
* *
* Saves contents to file * Saves contents to file
* *
* @param $filename * @param string $filename
* @param $contents * @param string $contents
* @see \Codeception\Module\Filesystem::writeToFile() * @see \Codeception\Module\Filesystem::writeToFile()
*/ */
public function writeToFile($filename, $contents) { public function writeToFile($filename, $contents) {

View File

@ -1,4 +1,4 @@
<?php //[STAMP] ffada6587f597b23930f2f63d3309fd0 <?php //[STAMP] d2a298893573661fdbd787dcfa27a7b0
namespace _generated; namespace _generated;
// This class was automatically generated by build task // This class was automatically generated by build task
@ -15,4 +15,18 @@ trait FunctionalTesterActions
abstract protected function getScenario(); abstract protected function getScenario();
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
} }

View File

@ -1,4 +1,4 @@
<?php //[STAMP] c871459f363e639d6d4c21f535bb78f4 <?php //[STAMP] 1467e0d5027bbc2413077351642a21f3
namespace _generated; namespace _generated;
// This class was automatically generated by build task // This class was automatically generated by build task
@ -19,16 +19,29 @@ trait UnitTesterActions
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
* Checks that two variables are equal. * Checks that two variables are equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values equal.
*
* Regular example:
* ```php
* <?php
* $I->assertEquals($element->getChildrenCount(), 5);
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertEquals($calculator->add(0.1, 0.2), 0.3, 'Calculator should add the two numbers correctly.', 0.01);
* ```
* *
* @param $expected * @param $expected
* @param $actual * @param $actual
* @param string $message * @param string $message
* * @param float $delta
* @return mixed
* @see \Codeception\Module\Asserts::assertEquals() * @see \Codeception\Module\Asserts::assertEquals()
*/ */
public function assertEquals($expected, $actual, $message = null) { public function assertEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args())); return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
} }
@ -36,14 +49,29 @@ trait UnitTesterActions
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
* Checks that two variables are not equal * Checks that two variables are not equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values not equal.
*
* Regular example:
* ```php
* <?php
* $I->assertNotEquals($element->getChildrenCount(), 0);
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertNotEquals($calculator->add(0.1, 0.2), 0.4, 'Calculator should add the two numbers correctly.', 0.01);
* ```
* *
* @param $expected * @param $expected
* @param $actual * @param $actual
* @param string $message * @param string $message
* @param float $delta
* @see \Codeception\Module\Asserts::assertNotEquals() * @see \Codeception\Module\Asserts::assertNotEquals()
*/ */
public function assertNotEquals($expected, $actual, $message = null) { public function assertNotEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args())); return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
} }
@ -56,8 +84,6 @@ trait UnitTesterActions
* @param $expected * @param $expected
* @param $actual * @param $actual
* @param string $message * @param string $message
*
* @return mixed
* @see \Codeception\Module\Asserts::assertSame() * @see \Codeception\Module\Asserts::assertSame()
*/ */
public function assertSame($expected, $actual, $message = null) { public function assertSame($expected, $actual, $message = null) {
@ -95,17 +121,6 @@ trait UnitTesterActions
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @deprecated
* @see \Codeception\Module\Asserts::assertGreaterThen()
*/
public function assertGreaterThen($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThen', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@ -121,17 +136,6 @@ trait UnitTesterActions
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @deprecated
* @see \Codeception\Module\Asserts::assertGreaterThenOrEqual()
*/
public function assertGreaterThenOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThenOrEqual', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@ -222,6 +226,36 @@ trait UnitTesterActions
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string starts with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsWith()
*/
public function assertStringStartsWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string doesn't start with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsNotWith()
*/
public function assertStringStartsNotWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@ -334,6 +368,138 @@ trait UnitTesterActions
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expected
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertGreaterOrEquals()
*/
public function assertGreaterOrEquals($expected, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expected
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertLessOrEquals()
*/
public function assertLessOrEquals($expected, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertIsEmpty()
*/
public function assertIsEmpty($actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $key
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertArrayHasKey()
*/
public function assertArrayHasKey($key, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $key
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertArrayNotHasKey()
*/
public function assertArrayNotHasKey($key, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expectedCount
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertCount()
*/
public function assertCount($expectedCount, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCount', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $class
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertInstanceOf()
*/
public function assertInstanceOf($class, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $class
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertNotInstanceOf()
*/
public function assertNotInstanceOf($class, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $type
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertInternalType()
*/
public function assertInternalType($type, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@ -345,4 +511,38 @@ trait UnitTesterActions
public function fail($message) { public function fail($message) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args())); return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args()));
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Handles and checks exception called inside callback function.
* Either exception class name or exception instance should be provided.
*
* ```php
* <?php
* $I->expectException(MyException::class, function() {
* $this->doSomethingBad();
* });
*
* $I->expectException(new MyException(), function() {
* $this->doSomethingBad();
* });
* ```
* If you want to check message or exception code, you can pass them with exception instance:
* ```php
* <?php
* // will check that exception MyException is thrown with "Don't do bad things" message
* $I->expectException(new MyException("Don't do bad things"), function() {
* $this->doSomethingBad();
* });
* ```
*
* @param $exception string or \Exception
* @param $callback
* @see \Codeception\Module\Asserts::expectException()
*/
public function expectException($exception, $callback) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args()));
}
} }

View File

@ -7,8 +7,6 @@
class_name: AcceptanceTester class_name: AcceptanceTester
modules: modules:
enabled: enabled:
# - PhpBrowser:
# url: http://localhost/myapp
- \Helper\Acceptance - \Helper\Acceptance
- Cli - Cli
- Filesystem - Filesystem

View File

@ -8,7 +8,6 @@ $I->seeFileFound('./app/Http/Controllers/TestsController.php');
$I->openFile('./app/Http/Controllers/TestsController.php'); $I->openFile('./app/Http/Controllers/TestsController.php');
$I->seeFileContentsEqual('<?php namespace App\Http\Controllers; $I->seeFileContentsEqual('<?php namespace App\Http\Controllers;
class TestsController extends Controller { class TestsController extends Controller {
const MODEL = "App\\Test"; const MODEL = "App\\Test";
@ -26,7 +25,6 @@ $I->seeFileFound('./app/Http/Controllers/CategoriesController.php');
$I->openFile('./app/Http/Controllers/CategoriesController.php'); $I->openFile('./app/Http/Controllers/CategoriesController.php');
$I->seeFileContentsEqual('<?php namespace App\Http\Controllers; $I->seeFileContentsEqual('<?php namespace App\Http\Controllers;
class CategoriesController extends Controller { class CategoriesController extends Controller {
const MODEL = "App\\Models\\Category"; const MODEL = "App\\Models\\Category";

View File

@ -2,7 +2,7 @@
$I = new AcceptanceTester($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('generate the REST actions trait'); $I->wantTo('generate the REST actions trait');
$I->runShellCommand('php artisan wn:controller:rest-actions'); $I->runShellCommand('php artisan wn:controller:rest-actions --force=true');
$I->seeInShellOutput('REST actions trait generated'); $I->seeInShellOutput('REST actions trait generated');
$I->seeFileFound('./app/Http/Controllers/RESTActions.php'); $I->seeFileFound('./app/Http/Controllers/RESTActions.php');
$I->openFile('./app/Http/Controllers/RESTActions.php'); $I->openFile('./app/Http/Controllers/RESTActions.php');

View File

@ -1,69 +1,68 @@
<?php <?php
// $I = new AcceptanceTester($scenario); $I = new AcceptanceTester($scenario);
// $I->wantTo('generate model factories without fields'); $I->wantTo('generate model factories without fields');
// $I->runShellCommand('php artisan wn:factory "App\Task"'); $I->runShellCommand('php artisan wn:factory "App\Task"');
// $I->seeInShellOutput('App\Task factory generated'); $I->seeInShellOutput('App\Task factory generated');
// $I->openFile('./database/factories/ModelFactory.php'); $I->openFile('./database/factories/ModelFactory.php');
// $I->seeInThisFile(' $I->seeInThisFile('
// $factory->define(App\Task::class, function ($faker) { $factory->define(App\Task::class, function ($faker) {
// return [ return [
// // Fields here // Fields here
// ]; ];
// });'); });');
// $I->writeToFile('./database/factories/ModelFactory.php', "<?php $I->writeToFile('./database/factories/ModelFactory.php', "<?php
// /* /*
// |-------------------------------------------------------------------------- |--------------------------------------------------------------------------
// | Model Factories | Model Factories
// |-------------------------------------------------------------------------- |--------------------------------------------------------------------------
// | |
// | Here you may define all of your model factories. Model factories give | Here you may define all of your model factories. Model factories give
// | you a convenient way to create models for testing and seeding your | you a convenient way to create models for testing and seeding your
// | database. Just tell the factory how a default model should look. | database. Just tell the factory how a default model should look.
// | |
// */ */
// \$factory->define(App\User::class, function (\$faker) { \$factory->define(App\User::class, function (\$faker) {
// return [ return [
// 'name' => \$faker->name, 'name' => \$faker->name,
// 'email' => \$faker->email, 'email' => \$faker->email,
// 'password' => str_random(10), 'password' => str_random(10),
// 'remember_token' => str_random(10), 'remember_token' => str_random(10),
// ]; ];
// }); });
// "); ");
// $I->wantTo('generate model factories with fields'); $I->wantTo('generate model factories with fields');
// $I->runShellCommand('php artisan wn:factory "App\Task" --fields="title:sentence(3),description:paragraph(3),due:date,hidden:boolean"'); $I->runShellCommand('php artisan wn:factory "App\Task" --fields="title:sentence(3),description:paragraph(3),due:date,hidden:boolean"');
// $I->seeInShellOutput('App\Task factory generated'); $I->seeInShellOutput('App\Task factory generated');
// $I->openFile('./database/factories/ModelFactory.php'); $I->openFile('./database/factories/ModelFactory.php');
// $I->seeInThisFile(" $I->seeInThisFile(
// 'title' => \$faker->sentence(3), " 'title' => \$faker->sentence(3)," . PHP_EOL .
// 'description' => \$faker->paragraph(3), " 'description' => \$faker->paragraph(3)," . PHP_EOL .
// 'due' => \$faker->date, " 'due' => \$faker->date," . PHP_EOL .
// 'hidden' => \$faker->boolean, " 'hidden' => \$faker->boolean,"
// "); );
// $I->writeToFile('./database/factories/ModelFactory.php', "<?php $I->writeToFile('./database/factories/ModelFactory.php', "<?php
// /* /*
// |-------------------------------------------------------------------------- |--------------------------------------------------------------------------
// | Model Factories | Model Factories
// |-------------------------------------------------------------------------- |--------------------------------------------------------------------------
// | |
// | Here you may define all of your model factories. Model factories give | Here you may define all of your model factories. Model factories give
// | you a convenient way to create models for testing and seeding your | you a convenient way to create models for testing and seeding your
// | database. Just tell the factory how a default model should look. | database. Just tell the factory how a default model should look.
// | |
// */ */
// \$factory->define(App\User::class, function (\$faker) {
// return [
// 'name' => \$faker->name,
// 'email' => \$faker->email,
// 'password' => str_random(10),
// 'remember_token' => str_random(10),
// ];
// });
// ");
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
");

View File

@ -2,7 +2,7 @@
$I = new AcceptanceTester($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('generate a migration without schema'); $I->wantTo('generate a migration without schema');
$I->runShellCommand('php artisan wn:migration tasks --file=create_tasks'); $I->runShellCommand('php artisan wn:migration tasks --add=timestamps --file=create_tasks');
$I->seeInShellOutput('tasks migration generated'); $I->seeInShellOutput('tasks migration generated');
$I->seeFileFound('./database/migrations/create_tasks.php'); $I->seeFileFound('./database/migrations/create_tasks.php');
$I->openFile('./database/migrations/create_tasks.php'); $I->openFile('./database/migrations/create_tasks.php');
@ -32,8 +32,39 @@ class CreateTasksTable extends Migration
'); ');
$I->deleteFile('./database/migrations/create_tasks.php'); $I->deleteFile('./database/migrations/create_tasks.php');
$I->wantTo('generate a migration without schema or timestamps');
$I->runShellCommand('php artisan wn:migration tasks --file=create_tasks');
$I->seeInShellOutput('tasks migration generated');
$I->seeFileFound('./database/migrations/create_tasks.php');
$I->openFile('./database/migrations/create_tasks.php');
$I->seeFileContentsEqual('<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTasksTable extends Migration
{
public function up()
{
Schema::create(\'tasks\', function(Blueprint $table) {
$table->increments(\'id\');
// Schema declaration
// Constraints declaration
});
}
public function down()
{
Schema::drop(\'tasks\');
}
}
');
$I->deleteFile('./database/migrations/create_tasks.php');
$I->wantTo('generate a migration with schema'); $I->wantTo('generate a migration with schema');
$I->runShellCommand('php artisan wn:migration tasks --file=create_tasks --schema="amount:decimal.5,2:after.\'size\':default.8 title:string:nullable"'); $I->runShellCommand('php artisan wn:migration tasks --add=timestamps --file=create_tasks --schema="amount:decimal.5,2:after.\'size\':default.8 title:string:nullable"');
$I->seeInShellOutput('tasks migration generated'); $I->seeInShellOutput('tasks migration generated');
$I->seeFileFound('./database/migrations/create_tasks.php'); $I->seeFileFound('./database/migrations/create_tasks.php');
$I->openFile('./database/migrations/create_tasks.php'); $I->openFile('./database/migrations/create_tasks.php');
@ -69,11 +100,24 @@ $I->runShellCommand('php artisan wn:migration tasks --file=create_tasks --keys="
$I->seeInShellOutput('tasks migration generated'); $I->seeInShellOutput('tasks migration generated');
$I->seeFileFound('./database/migrations/create_tasks.php'); $I->seeFileFound('./database/migrations/create_tasks.php');
$I->openFile('./database/migrations/create_tasks.php'); $I->openFile('./database/migrations/create_tasks.php');
$I->seeInThisFile('$table->foreign(\'category_type_id\') $I->seeInThisFile(
->references(\'id\') "\$table->foreign('category_type_id')\n".
->on(\'category_types\');'); " ->references('id')\n".
$I->seeInThisFile('$table->foreign(\'user_id\') " ->on('category_types');"
->references(\'identifier\') );
->on(\'members\') $I->seeInThisFile(
->onDelete(\'cascade\');'); "\$table->foreign('user_id')\n".
" ->references('identifier')\n".
" ->on('members')". PHP_EOL .
" ->onDelete('cascade');");
$I->deleteFile('./database/migrations/create_tasks.php');
$I->wantTo('generate a migration with additional columns');
$I->runShellCommand('php artisan wn:migration tasks --file=create_tasks --add=softDeletes,nullableTimestamps');
$I->seeInShellOutput('tasks migration generated');
$I->seeFileFound('./database/migrations/create_tasks.php');
$I->openFile('./database/migrations/create_tasks.php');
$I->dontSeeInThisFile("\$table->timestamps();");
$I->seeInThisFile("\$table->softDeletes();");
$I->seeInThisFile("\$table->nullableTimestamps();");
$I->deleteFile('./database/migrations/create_tasks.php'); $I->deleteFile('./database/migrations/create_tasks.php');

View File

@ -2,7 +2,7 @@
$I = new AcceptanceTester($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('generate a model without fillable fields or dates'); $I->wantTo('generate a model without fillable fields or dates');
$I->runShellCommand('php artisan wn:model TestingModel --path=tests/tmp'); $I->runShellCommand('php artisan wn:model TestingModel --path=tests/tmp --force=true');
$I->seeInShellOutput('TestingModel model generated'); $I->seeInShellOutput('TestingModel model generated');
$I->seeFileFound('./tests/tmp/TestingModel.php'); $I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php'); $I->openFile('./tests/tmp/TestingModel.php');
@ -25,18 +25,49 @@ class TestingModel extends Model {
} }
'); ');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model without fillable fields, dates or timestamps');
$I->runShellCommand('php artisan wn:model TestingModel --path=tests/tmp --force=true --timestamps=false');
$I->seeInShellOutput('TestingModel model generated');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
$I->seeFileContentsEqual('<?php namespace Tests\Tmp;
use Illuminate\Database\Eloquent\Model;
class TestingModel extends Model {
protected $fillable = [];
protected $dates = [];
public static $rules = [
// Validation rules
];
public $timestamps = false;
// Relationships
}
');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with fillable fields'); $I->wantTo('generate a model with fillable fields');
$I->runShellCommand('php artisan wn:model TestingModel --fillable=name,title --path=tests/tmp'); $I->runShellCommand('php artisan wn:model TestingModel --fillable=name,title --path=tests/tmp');
$I->seeFileFound('./tests/tmp/TestingModel.php'); $I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php'); $I->openFile('./tests/tmp/TestingModel.php');
$I->seeInThisFile('protected $fillable = ["name", "title"];'); $I->seeInThisFile('protected $fillable = ["name", "title"];');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with dates fields'); $I->wantTo('generate a model with dates fields');
$I->runShellCommand('php artisan wn:model TestingModel --dates=started_at --path=tests/tmp'); $I->runShellCommand('php artisan wn:model TestingModel --dates=started_at --path=tests/tmp');
$I->seeFileFound('./tests/tmp/TestingModel.php'); $I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php'); $I->openFile('./tests/tmp/TestingModel.php');
$I->seeInThisFile('protected $dates = ["started_at"];'); $I->seeInThisFile('protected $dates = ["started_at"];');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with relations'); $I->wantTo('generate a model with relations');
$I->runShellCommand('php artisan wn:model TestingModel --has-many=accounts --belongs-to="owner:App\User" --has-one=number:Phone --path=tests/tmp'); $I->runShellCommand('php artisan wn:model TestingModel --has-many=accounts --belongs-to="owner:App\User" --has-one=number:Phone --path=tests/tmp');
@ -60,17 +91,44 @@ $I->seeInThisFile('
return $this->hasOne("Tests\\Tmp\\Phone"); return $this->hasOne("Tests\\Tmp\\Phone");
} }
'); ');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with validation rules'); $I->wantTo('generate a model with validation rules');
$I->runShellCommand('php artisan wn:model TestingModel --rules="name=required age=integer|min:13 email=email|unique:users,email_address" --path=tests/tmp'); $I->runShellCommand('php artisan wn:model TestingModel --rules="name=required age=integer|min:13 email=email|unique:users,email_address" --path=tests/tmp');
$I->seeFileFound('./tests/tmp/TestingModel.php'); $I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php'); $I->openFile('./tests/tmp/TestingModel.php');
$I->seeInThisFile(' $I->seeInThisFile(
public static $rules = [ " public static \$rules = [\n" .
"name" => "required", " \"name\" => \"required\"," . PHP_EOL .
"age" => "integer|min:13", " \"age\" => \"integer|min:13\"," . PHP_EOL .
"email" => "email|unique:users,email_address", " \"email\" => \"email|unique:users,email_address\",\n".
]; " ];"
'); );
$I->deleteFile('./tests/tmp/TestingModel.php'); $I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with softDeletes');
$I->runShellCommand('php artisan wn:model TestingModel --soft-deletes=true --path=tests/tmp --force=true');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
$I->seeFileContentsEqual('<?php namespace Tests\Tmp;
use Illuminate\Database\Eloquent\Model;
class TestingModel extends Model {
use \Illuminate\Database\Eloquent\SoftDeletes;
protected $fillable = [];
protected $dates = [];
public static $rules = [
// Validation rules
];
// Relationships
}
');
$I->deleteFile('./tests/tmp/TestingModel.php');

View File

@ -0,0 +1,29 @@
<?php
$I = new AcceptanceTester($scenario);
// $I->wantTo('generate a pivot table seeder');
// $I->runShellCommand('php artisan wn:pivot-seeder tasks ShortTag');
// $I->seeInShellOutput('ShortTagTaskTableSeeder generated');
// $I->openFile('./database/seeds/ShortTagTaskTableSeeder.php');
// $I->seeInThisFile("
// use Illuminate\Database\Seeder;
// use Faker\Factory as Faker;
// class ShortTagTaskTableSeeder extends Seeder
// {
// public function run()
// {
// \$faker = Faker::create();
// \$firstIds = DB::table('short_tags')->lists('id');
// \$secondIds = DB::table('tasks')->lists('id');
// for(\$i = 0; \$i < 10; \$i++) {
// DB::table('short_tag_task')->insert([
// 'short_tag_id' => \$faker->randomElement(\$firstIds),
// 'task_id' => \$faker->randomElement(\$secondIds)
// ]);
// }
// }
// }");
// $I->deleteFile('./database/seeds/ShortTagTaskTableSeeder.php');

View File

@ -2,7 +2,7 @@
$I = new AcceptanceTester($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('generate a pivot table'); $I->wantTo('generate a pivot table');
$I->runShellCommand('php artisan wn:pivot-table Tag Project --file=pivot_table'); $I->runShellCommand('php artisan wn:pivot-table Tag Project --add=timestamps --file=pivot_table');
$I->seeInShellOutput('project_tag migration generated'); $I->seeInShellOutput('project_tag migration generated');
$I->seeFileFound('./database/migrations/pivot_table.php'); $I->seeFileFound('./database/migrations/pivot_table.php');
$I->openFile('./database/migrations/pivot_table.php'); $I->openFile('./database/migrations/pivot_table.php');

View File

@ -2,7 +2,7 @@
$I = new AcceptanceTester($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('generate a RESTful resource'); $I->wantTo('generate a RESTful resource');
$I->runShellCommand('php artisan wn:resource task_category "name;string:unique;requied;fillable;word descr;text:nullable;;fillable;paragraph project_id;integer;required;key,fillable due;timestamp;;fillable,date;date" --has-many="tags,tasks" --belongs-to="project,creator:User" --migration-file=create_task_categories'); $I->runShellCommand('php artisan wn:resource task_category "name;string:unique;requied;fillable;word descr;text:nullable;;fillable;paragraph due;timestamp;;fillable,date;date" --has-many="tags,tasks" --belongs-to="project,creator:User" --add=timestamps --migration-file=create_task_categories');
// Checking the model // Checking the model
$I->seeInShellOutput('TaskCategory model generated'); $I->seeInShellOutput('TaskCategory model generated');
@ -11,29 +11,31 @@ $I->openFile('./app/TaskCategory.php');
$I->seeInThisFile('namespace App;'); $I->seeInThisFile('namespace App;');
$I->seeInThisFile('class TaskCategory extends Model'); $I->seeInThisFile('class TaskCategory extends Model');
$I->seeInThisFile('protected $fillable = ["name", "descr", "project_id", "due"];'); $I->seeInThisFile('protected $fillable = ["name", "descr", "due", "project_id", "user_id"];');
$I->seeInThisFile('protected $dates = ["due"];'); $I->seeInThisFile('protected $dates = ["due"];');
$I->seeInThisFile('public static $rules = [ $I->seeInThisFile(
"name" => "requied", "public static \$rules = [\n".
"project_id" => "required", " \"name\" => \"requied\"," . PHP_EOL .
];'); " \"project_id\" => \"required|numeric\"," . PHP_EOL .
$I->seeInThisFile(' " \"user_id\" => \"required|numeric\",\n".
public function tags() " ];");
$I->seeInThisFile(
' public function tags()
{ {
return $this->hasMany("App\Tag"); return $this->hasMany("App\Tag");
} }');
$I->seeInThisFile(
public function tasks() ' public function tasks()
{ {
return $this->hasMany("App\Task"); return $this->hasMany("App\Task");
} }');
$I->seeInThisFile(
public function project() ' public function project()
{ {
return $this->belongsTo("App\Project"); return $this->belongsTo("App\Project");
} }');
$I->seeInThisFile(
public function creator() ' public function creator()
{ {
return $this->belongsTo("App\User"); return $this->belongsTo("App\User");
}'); }');
@ -45,17 +47,20 @@ $I->seeFileFound('./database/migrations/create_task_categories.php');
$I->openFile('./database/migrations/create_task_categories.php'); $I->openFile('./database/migrations/create_task_categories.php');
$I->seeInThisFile('class CreateTaskCategoriesTable extends Migration'); $I->seeInThisFile('class CreateTaskCategoriesTable extends Migration');
$I->seeInThisFile('Schema::create(\'task_categories\', function(Blueprint $table) { $I->seeInThisFile("Schema::create('task_categories', function(Blueprint \$table) {\n".
$table->increments(\'id\'); " \$table->increments('id');\n".
$table->string(\'name\')->unique(); " \$table->string('name')->unique();" . PHP_EOL .
$table->text(\'descr\')->nullable(); " \$table->text('descr')->nullable();" . PHP_EOL .
$table->integer(\'project_id\'); " \$table->timestamp('due');" . PHP_EOL .
$table->timestamp(\'due\'); " \$table->integer('project_id')->unsigned();" . PHP_EOL.
$table->foreign(\'project_id\') " \$table->integer('user_id')->unsigned();\n" .
->references(\'id\') " \$table->foreign('project_id')\n".
->on(\'projects\'); " ->references('id')\n".
$table->timestamps(); " ->on('projects');" . PHP_EOL .
});'); " \$table->foreign('user_id')\n".
" ->references('id')\n".
" ->on('users');\n".
" \$table->timestamps();");
$I->deleteFile('./database/migrations/create_task_categories.php'); $I->deleteFile('./database/migrations/create_task_categories.php');
@ -106,8 +111,8 @@ $app->get("/", function () use ($app) {
// Checking model factory // Checking model factory
// $I->openFile('./database/factories/ModelFactory.php'); // $I->openFile('./database/factories/ModelFactory.php');
// $I->seeInThisFile(" // $I->seeInThisFile(
// /** // "/**
// * Factory definition for model App\TaskCategory. // * Factory definition for model App\TaskCategory.
// */ // */
// \$factory->define(App\TaskCategory::class, function (\$faker) { // \$factory->define(App\TaskCategory::class, function (\$faker) {
@ -117,25 +122,39 @@ $app->get("/", function () use ($app) {
// 'due' => \$faker->date, // 'due' => \$faker->date,
// ]; // ];
// });"); // });");
// $I->writeToFile('./database/factories/ModelFactory.php', "<?php $I->writeToFile('./database/factories/ModelFactory.php', "<?php
// /* /*
// |-------------------------------------------------------------------------- |--------------------------------------------------------------------------
// | Model Factories | Model Factories
// |-------------------------------------------------------------------------- |--------------------------------------------------------------------------
// | |
// | Here you may define all of your model factories. Model factories give | Here you may define all of your model factories. Model factories give
// | you a convenient way to create models for testing and seeding your | you a convenient way to create models for testing and seeding your
// | database. Just tell the factory how a default model should look. | database. Just tell the factory how a default model should look.
// | |
// */ */
// \$factory->define(App\User::class, function (\$faker) { \$factory->define(App\User::class, function (\$faker) {
// return [ return [
// 'name' => \$faker->name, 'name' => \$faker->name,
// 'email' => \$faker->email, 'email' => \$faker->email,
// 'password' => str_random(10), 'password' => str_random(10),
// 'remember_token' => str_random(10), 'remember_token' => str_random(10),
// ]; ];
// }); });
// "); ");
// Checking database seeder
// $I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
// $I->seeInThisFile('
// use Illuminate\Database\Seeder;
// class TaskCategoriesTableSeeder extends Seeder
// {
// public function run()
// {
// factory(App\TaskCategory::class, 10)->create();
// }
// }');
// $I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');

View File

@ -0,0 +1,136 @@
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('Generate RESTful resources from a file');
$I->writeToFile('database/database.sqlite', '');
$I->runShellCommand('php artisan wn:resources tests/_data/ResourcesTest.yml');
// Checking the model
$I->seeInShellOutput('Author model generated');
$I->seeInShellOutput('Book model generated');
$I->seeInShellOutput('Library model generated');
$I->seeFileFound('./app/Author.php');
$I->seeFileFound('./app/Book.php');
$I->seeFileFound('./app/Library.php');
$I->deleteFile('./app/Author.php');
$I->deleteFile('./app/Book.php');
$I->deleteFile('./app/Library.php');
// Checking the migration
$I->seeInShellOutput('authors migration generated');
$I->seeInShellOutput('books migration generated');
$I->seeInShellOutput('libraries migration generated');
// Can't check for specific file names, so we'll just strip the directory
$I->cleanDir('database/migrations');
$I->writeToFile('database/migrations/.gitkeep', '');
// Checking the RESTActions trait
$I->seeFileFound('./app/Http/Controllers/RESTActions.php');
$I->deleteFile('./app/Http/Controllers/RESTActions.php');
// Checking the controller
$I->seeInShellOutput('AuthorsController generated');
$I->seeInShellOutput('LibrariesController generated');
$I->seeInShellOutput('BooksController generated');
$I->seeFileFound('./app/Http/Controllers/AuthorsController.php');
$I->seeFileFound('./app/Http/Controllers/LibrariesController.php');
$I->seeFileFound('./app/Http/Controllers/BooksController.php');
$I->deleteFile('./app/Http/Controllers/AuthorsController.php');
$I->deleteFile('./app/Http/Controllers/LibrariesController.php');
$I->deleteFile('./app/Http/Controllers/BooksController.php');
// Checking routes
$I->openFile('./app/Http/routes.php');
$I->seeInThisFile('
$app->get(\'author\', \'AuthorsController@all\');
$app->get(\'author/{id}\', \'AuthorsController@get\');
$app->post(\'author\', \'AuthorsController@add\');
$app->put(\'author/{id}\', \'AuthorsController@put\');
$app->delete(\'author/{id}\', \'AuthorsController@remove\');');
$I->seeInThisFile('
$app->get(\'book\', \'BooksController@all\');
$app->get(\'book/{id}\', \'BooksController@get\');
$app->post(\'book\', \'BooksController@add\');
$app->put(\'book/{id}\', \'BooksController@put\');
$app->delete(\'book/{id}\', \'BooksController@remove\');');
$I->seeInThisFile('
$app->get(\'library\', \'LibrariesController@all\');
$app->get(\'library/{id}\', \'LibrariesController@get\');
$app->post(\'library\', \'LibrariesController@add\');
$app->put(\'library/{id}\', \'LibrariesController@put\');
$app->delete(\'library/{id}\', \'LibrariesController@remove\');');
$I->writeToFile('./app/Http/routes.php', '<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$app->get("/", function () use ($app) {
return $app->welcome();
});
');
// Checking model factory
// $I->openFile('./database/factories/ModelFactory.php');
// $I->seeInThisFile(
// "/**
// * Factory definition for model App\TaskCategory.
// */
// \$factory->define(App\TaskCategory::class, function (\$faker) {
// return [
// 'name' => \$faker->word,
// 'descr' => \$faker->paragraph,
// 'due' => \$faker->date,
// ];
// });");
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
");
$I->deleteFile('database/database.sqlite');
// Checking database seeder
// $I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
// $I->seeInThisFile('
// use Illuminate\Database\Seeder;
// class TaskCategoriesTableSeeder extends Seeder
// {
// public function run()
// {
// factory(App\TaskCategory::class, 10)->create();
// }
// }');
// $I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');

View File

@ -0,0 +1,124 @@
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('Generate RESTful resources from a file with Laravel Routes');
$I->writeToFile('database/database.sqlite', '');
$I->runShellCommand('php artisan wn:resources tests/_data/ResourcesTest.yml --laravel=true');
// Checking the model
$I->seeInShellOutput('Author model generated');
$I->seeInShellOutput('Book model generated');
$I->seeInShellOutput('Library model generated');
$I->seeFileFound('./app/Author.php');
$I->seeFileFound('./app/Book.php');
$I->seeFileFound('./app/Library.php');
$I->deleteFile('./app/Author.php');
$I->deleteFile('./app/Book.php');
$I->deleteFile('./app/Library.php');
// Checking the migration
$I->seeInShellOutput('authors migration generated');
$I->seeInShellOutput('books migration generated');
$I->seeInShellOutput('libraries migration generated');
// Can't check for specific file names, so we'll just strip the directory
$I->cleanDir('database/migrations');
$I->writeToFile('database/migrations/.gitkeep', '');
// Checking the RESTActions trait
$I->seeFileFound('./app/Http/Controllers/RESTActions.php');
$I->deleteFile('./app/Http/Controllers/RESTActions.php');
// Checking the controller
$I->seeInShellOutput('AuthorsController generated');
$I->seeInShellOutput('LibrariesController generated');
$I->seeInShellOutput('BooksController generated');
$I->seeFileFound('./app/Http/Controllers/AuthorsController.php');
$I->seeFileFound('./app/Http/Controllers/LibrariesController.php');
$I->seeFileFound('./app/Http/Controllers/BooksController.php');
$I->deleteFile('./app/Http/Controllers/AuthorsController.php');
$I->deleteFile('./app/Http/Controllers/LibrariesController.php');
$I->deleteFile('./app/Http/Controllers/BooksController.php');
$I->seeFileFound('./routes/api.php');
$I->seeInThisFile('
Route::get(\'author\', \'AuthorsController@all\');
Route::get(\'author/{id}\', \'AuthorsController@get\');
Route::post(\'author\', \'AuthorsController@add\');
Route::put(\'author/{id}\', \'AuthorsController@put\');
Route::delete(\'author/{id}\', \'AuthorsController@remove\');');
$I->seeInThisFile('
Route::get(\'book\', \'BooksController@all\');
Route::get(\'book/{id}\', \'BooksController@get\');
Route::post(\'book\', \'BooksController@add\');
Route::put(\'book/{id}\', \'BooksController@put\');
Route::delete(\'book/{id}\', \'BooksController@remove\');');
$I->seeInThisFile('
Route::get(\'library\', \'LibrariesController@all\');
Route::get(\'library/{id}\', \'LibrariesController@get\');
Route::post(\'library\', \'LibrariesController@add\');
Route::put(\'library/{id}\', \'LibrariesController@put\');
Route::delete(\'library/{id}\', \'LibrariesController@remove\');');
$I->writeToFile('./app/Http/routes.php', '<?php
/*
|------------------------------------------
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|------------------------------------------
*/
');
// Checking model factory
// $I->openFile('./database/factories/ModelFactory.php');
// $I->seeInThisFile(
// "/**
// * Factory definition for model App\TaskCategory.
// */
// \$factory->define(App\TaskCategory::class, function (\$faker) {
// return [
// 'name' => \$faker->word,
// 'descr' => \$faker->paragraph,
// 'due' => \$faker->date,
// ];
// });");
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
");
$I->deleteFile('database/database.sqlite');
// Checking database seeder
// $I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
// $I->seeInThisFile('
// use Illuminate\Database\Seeder;
// class TaskCategoriesTableSeeder extends Seeder
// {
// public function run()
// {
// factory(App\TaskCategory::class, 10)->create();
// }
// }');
// $I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');

View File

@ -59,3 +59,38 @@ $app->get("/", function () use ($app) {
return $app->welcome(); return $app->welcome();
}); });
'); ');
$I->wantTo('run wn:routes in Lumen 5.3+');
if(!file_exists('./routes')) {
mkdir('./routes');
}
$I->writeToFile('./routes/web.php', '<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$app->get("/", function () use ($app) {
return $app->version();
});
');
$I->runShellCommand('php artisan wn:route foo --controller=customController');
$I->seeInShellOutput('foo routes generated');
$I->openFile('./routes/web.php');
$I->seeInThisFile("
\$app->get('foo', 'customController@all');
\$app->get('foo/{id}', 'customController@get');
\$app->post('foo', 'customController@add');
\$app->put('foo/{id}', 'customController@put');
\$app->delete('foo/{id}', 'customController@remove');
");
$I->deleteDir('./routes');

View File

@ -0,0 +1,34 @@
<?php
$I = new AcceptanceTester($scenario);
// $I->wantTo('generate a seeder with default options');
// $I->runShellCommand('php artisan wn:seeder "App\Task"');
// $I->seeInShellOutput('TasksTableSeeder generated');
// $I->openFile('./database/seeds/TasksTableSeeder.php');
// $I->seeInThisFile('
// use Illuminate\Database\Seeder;
// class TasksTableSeeder extends Seeder
// {
// public function run()
// {
// factory(App\Task::class, 10)->create();
// }
// }');
// $I->deleteFile('./database/seeds/TasksTableSeeder.php');
// $I->wantTo('generate a seeder with custom options');
// $I->runShellCommand('php artisan wn:seeder "App\Category" --count=25');
// $I->seeInShellOutput('CategoriesTableSeeder generated');
// $I->openFile('./database/seeds/CategoriesTableSeeder.php');
// $I->seeInThisFile('
// use Illuminate\Database\Seeder;
// class CategoriesTableSeeder extends Seeder
// {
// public function run()
// {
// factory(App\Category::class, 25)->create();
// }
// }');
// $I->deleteFile('./database/seeds/CategoriesTableSeeder.php');

View File

@ -138,7 +138,7 @@ class ArgumentFormatLoader {
$attr = $matches['attr']; $attr = $matches['attr'];
$type = empty($matches['type']) ? null : $matches['type']; $type = empty($matches['type']) ? null : $matches['type'];
$isArray = (@$matches[2][0] === '['); $isArray = (isset($matches[2][0]) && $matches[2][0] === '[');
return [$attr, $type, $isArray]; return [$attr, $type, $isArray];
} }

View File

@ -31,10 +31,15 @@ class BaseCommand extends Command {
return new ArgumentParser($format); return new ArgumentParser($format);
} }
protected function save($content, $path) protected function save($content, $path, $name, $force = false)
{ {
if (!$force && $this->fs->exists($path) && $this->input->hasOption('force') && !$this->option('force')) {
$this->info("{$name} already exists; use --force option to override it !");
return;
}
$this->makeDirectory($path); $this->makeDirectory($path);
$this->fs->put($path, $content); $this->fs->put($path, $content);
$this->info("{$name} generated !");
} }
protected function makeDirectory($path) protected function makeDirectory($path)
@ -44,4 +49,9 @@ class BaseCommand extends Command {
} }
} }
protected function spaces($n)
{
return str_repeat(' ', $n);
}
} }

View File

@ -1,11 +1,16 @@
<?php namespace Wn\Generators\Commands; <?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class ControllerCommand extends BaseCommand { class ControllerCommand extends BaseCommand {
protected $signature = 'wn:controller protected $signature = 'wn:controller
{model : Name of the model (with namespace if not App)} {model : Name of the model (with namespace if not App)}
{--no-routes= : without routes}'; {--no-routes= : without routes}
{--force= : override the existing files}
{--laravel : Use Laravel style route definitions}
';
protected $description = 'Generates RESTful controller using the RESTActions trait'; protected $description = 'Generates RESTful controller using the RESTActions trait';
@ -28,15 +33,18 @@ class ControllerCommand extends BaseCommand {
]) ])
->get(); ->get();
$this->save($content, "./app/Http/Controllers/{$controller}.php"); $this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
$this->info("{$controller} generated !");
if(! $this->option('no-routes')){ if(! $this->option('no-routes')){
$this->call('wn:route', [ $options = [
'resource' => snake_case($name, '-'), 'resource' => snake_case($name, '-'),
'--controller' => $controller '--controller' => $controller,
]); ];
if ($this->option('laravel')) {
$options['--laravel'] = true;
}
$this->call('wn:route', $options);
} }
} }

View File

@ -3,7 +3,8 @@
class ControllerRestActionsCommand extends BaseCommand { class ControllerRestActionsCommand extends BaseCommand {
protected $signature = 'wn:controller:rest-actions'; protected $signature = 'wn:controller:rest-actions
{--force= : override the existing files}';
protected $description = 'Generates REST actions trait to use into controllers'; protected $description = 'Generates REST actions trait to use into controllers';
@ -11,9 +12,7 @@ class ControllerRestActionsCommand extends BaseCommand {
{ {
$content = $this->getTemplate('controller/rest-actions')->get(); $content = $this->getTemplate('controller/rest-actions')->get();
$this->save($content, "./app/Http/Controllers/RESTActions.php"); $this->save($content, "./app/Http/Controllers/RESTActions.php", "REST actions trait");
$this->info("REST actions trait generated !");
} }
} }

View File

@ -7,7 +7,9 @@ class FactoryCommand extends BaseCommand {
{model : full qualified name of the model.} {model : full qualified name of the model.}
{--fields= : the fields to generate.} {--fields= : the fields to generate.}
{--file= : the factories file.} {--file= : the factories file.}
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}'; {--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
{--force= : override the existing files}
';
protected $description = 'Generates a model factory'; protected $description = 'Generates a model factory';
@ -26,9 +28,7 @@ class FactoryCommand extends BaseCommand {
]) ])
->get(); ->get();
$this->save($content, $file); $this->save($content, $file, "{$model} factory", true);
$this->info("{$model} factory generated !");
} }
protected function getFile() protected function getFile()
@ -56,7 +56,7 @@ class FactoryCommand extends BaseCommand {
} }
$content = implode(PHP_EOL, $content); $content = implode(PHP_EOL, $content);
} else { } else {
$content = "\t\t// Fields here"; $content = " // Fields here";
} }
return $content; return $content;

View File

@ -6,9 +6,11 @@ class MigrationCommand extends BaseCommand {
protected $signature = 'wn:migration protected $signature = 'wn:migration
{table : The table name.} {table : The table name.}
{--schema= : the schema.} {--schema= : the schema.}
{--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.}
{--keys= : foreign keys.} {--keys= : foreign keys.}
{--file= : name of the migration file (to use only for testing purpose).} {--file= : name of the migration file (to use only for testing purpose).}
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options} {--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
{--force= : override the existing files}
'; ';
// {action : One of create, add, remove or drop options.} // {action : One of create, add, remove or drop options.}
// The action is only create for the moment // The action is only create for the moment
@ -19,31 +21,45 @@ class MigrationCommand extends BaseCommand {
{ {
$table = $this->argument('table'); $table = $this->argument('table');
$name = 'Create' . ucwords(camel_case($table)); $name = 'Create' . ucwords(camel_case($table));
$snakeName = snake_case($name);
$content = $this->getTemplate('migration') $content = $this->getTemplate('migration')
->with([ ->with([
'table' => $table, 'table' => $table,
'name' => $name, 'name' => $name,
'schema' => $this->getSchema(), 'schema' => $this->getSchema(),
'additionals' => $this->getAdditionals(),
'constraints' => $this->getConstraints() 'constraints' => $this->getConstraints()
]) ])
->get(); ->get();
$file = $this->option('file'); $file = $this->option('file');
if(! $file){ if(! $file){
$file = date('Y_m_d_His_') . snake_case($name) . '_table'; $file = date('Y_m_d_His_') . $snakeName . '_table';
$this->deleteOldMigration($snakeName);
}else{
$this->deleteOldMigration($file);
} }
$this->save($content, "./database/migrations/{$file}.php"); $this->save($content, "./database/migrations/{$file}.php", "{$table} migration");
}
$this->info("{$table} migration generated !"); protected function deleteOldMigration($fileName)
{
foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){
if($fileInfo->isDot()) continue;
if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){
unlink($fileInfo->getPathname());
}
}
} }
protected function getSchema() protected function getSchema()
{ {
$schema = $this->option('schema'); $schema = $this->option('schema');
if(! $schema){ if(! $schema){
return " // Schema declaration"; return $this->spaces(12) . "// Schema declaration";
} }
$items = $schema; $items = $schema;
@ -59,6 +75,23 @@ class MigrationCommand extends BaseCommand {
return implode(PHP_EOL, $fields); return implode(PHP_EOL, $fields);
} }
protected function getAdditionals()
{
$additionals = $this->option('add');
if (empty($additionals)) {
return '';
}
$additionals = explode(',', $additionals);
$lines = [];
foreach ($additionals as $add) {
$add = trim($add);
$lines[] = $this->spaces(12) . "\$table->{$add}();";
}
return implode(PHP_EOL, $lines);
}
protected function getFieldDeclaration($parts) protected function getFieldDeclaration($parts)
{ {
$name = $parts[0]['name']; $name = $parts[0]['name'];
@ -74,7 +107,7 @@ class MigrationCommand extends BaseCommand {
{ {
$keys = $this->option('keys'); $keys = $this->option('keys');
if(! $keys){ if(! $keys){
return " // Constraints declaration"; return $this->spaces(12) . "// Constraints declaration";
} }
$items = $keys; $items = $keys;

View File

@ -12,8 +12,12 @@ class ModelCommand extends BaseCommand {
{--belongs-to= : belongsTo relationships.} {--belongs-to= : belongsTo relationships.}
{--belongs-to-many= : belongsToMany relationships.} {--belongs-to-many= : belongsToMany relationships.}
{--rules= : fields validation rules.} {--rules= : fields validation rules.}
{--timestamps=true : enables timestamps on the model.}
{--path=app : where to store the model php file.} {--path=app : where to store the model php file.}
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}'; {--soft-deletes= : adds SoftDeletes trait to the model.}
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
{--force= : override the existing files}
';
protected $description = 'Generates a model class for a RESTfull resource'; protected $description = 'Generates a model class for a RESTfull resource';
@ -29,13 +33,13 @@ class ModelCommand extends BaseCommand {
'fillable' => $this->getAsArrayFields('fillable'), 'fillable' => $this->getAsArrayFields('fillable'),
'dates' => $this->getAsArrayFields('dates'), 'dates' => $this->getAsArrayFields('dates'),
'relations' => $this->getRelations(), 'relations' => $this->getRelations(),
'rules' => $this->getRules() 'rules' => $this->getRules(),
'additional' => $this->getAdditional(),
'uses' => $this->getUses()
]) ])
->get(); ->get();
$this->save($content, "./{$path}/{$name}.php"); $this->save($content, "./{$path}/{$name}.php", "{$name} model");
$this->info("{$name} model generated !");
} }
protected function getAsArrayFields($arg, $isOption = true) protected function getAsArrayFields($arg, $isOption = true)
@ -66,7 +70,7 @@ class ModelCommand extends BaseCommand {
); );
if(empty($relations)){ if(empty($relations)){
return "\t// Relationships"; return " // Relationships";
} }
return implode(PHP_EOL, $relations); return implode(PHP_EOL, $relations);
@ -99,7 +103,7 @@ class ModelCommand extends BaseCommand {
{ {
$rules = $this->option('rules'); $rules = $this->option('rules');
if(! $rules){ if(! $rules){
return "\t\t// Validation rules"; return " // Validation rules";
} }
$items = $rules; $items = $rules;
if(! $this->option('parsed')){ if(! $this->option('parsed')){
@ -114,4 +118,18 @@ class ModelCommand extends BaseCommand {
return implode(PHP_EOL, $rules); return implode(PHP_EOL, $rules);
} }
protected function getAdditional()
{
return $this->option('timestamps') == 'false'
? " public \$timestamps = false;" . PHP_EOL . PHP_EOL
: '';
}
protected function getUses()
{
return $this->option('soft-deletes') == 'true'
? ' use \Illuminate\Database\Eloquent\SoftDeletes;' . PHP_EOL . PHP_EOL
: '';
}
} }

View File

@ -0,0 +1,58 @@
<?php namespace Wn\Generators\Commands;
class PivotSeederCommand extends BaseCommand {
protected $signature = 'wn:pivot-seeder
{model1 : Name of the first model or table}
{model2 : Name of the second model or table}
{--count=10 : number of elements to add in database.}
{--force= : override the existing files}
';
protected $description = 'Generates seeder for pivot table';
public function handle()
{
$resources = $this->getResources();
$name = $this->getSeederName($resources);
$tables = $this->getTableNames($resources);
$file = "./database/seeds/{$name}.php";
$content = $this->getTemplate('pivot-seeder')
->with([
'first_resource' => $resources[0],
'second_resource' => $resources[1],
'first_table' => $tables[0],
'second_table' => $tables[1],
'name' => $name,
'count' => $this->option('count')
])
->get();
$this->save($content, $file, $name);
}
protected function getResources()
{
$resources = array_map(function($arg) {
return snake_case(str_singular($this->argument($arg)));
}, ['model1', 'model2']);
sort($resources);
return $resources;
}
protected function getSeederName($resources) {
$resources = array_map(function($resource){
return ucwords(camel_case($resource));
}, $resources);
return implode('', $resources) . 'TableSeeder';
}
protected function getTableNames($resources) {
return array_map('str_plural', $resources);
}
}

View File

@ -6,7 +6,9 @@ class PivotTableCommand extends BaseCommand {
protected $signature = 'wn:pivot-table protected $signature = 'wn:pivot-table
{model1 : Name of the first model or table} {model1 : Name of the first model or table}
{model2 : Name of the second model or table} {model2 : Name of the second model or table}
{--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.}
{--file= : name of the migration file (to use only for testing purpose).} {--file= : name of the migration file (to use only for testing purpose).}
{--force= : override the existing files}
'; ';
protected $description = 'Generates creation migration for a pivot table'; protected $description = 'Generates creation migration for a pivot table';
@ -22,7 +24,9 @@ class PivotTableCommand extends BaseCommand {
'--schema' => $this->schema(), '--schema' => $this->schema(),
'--keys' => $this->keys(), '--keys' => $this->keys(),
'--file' => $this->option('file'), '--file' => $this->option('file'),
'--parsed' => false '--parsed' => false,
'--force' => $this->option('force'),
'--add' => $this->option('add')
]); ]);
} }

View File

@ -1,6 +1,8 @@
<?php namespace Wn\Generators\Commands; <?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class ResourceCommand extends BaseCommand { class ResourceCommand extends BaseCommand {
protected $signature = 'wn:resource protected $signature = 'wn:resource
@ -11,7 +13,11 @@ class ResourceCommand extends BaseCommand {
{--belongs-to= : belongsTo relationships.} {--belongs-to= : belongsTo relationships.}
{--belongs-to-many= : belongsToMany relationships.} {--belongs-to-many= : belongsToMany relationships.}
{--migration-file= : the migration file name.} {--migration-file= : the migration file name.}
{--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.}
{--path=app : where to store the model file.}
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options} {--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
{--force= : override the existing files}
{--laravel= : Use Laravel style route definitions}
'; ';
protected $description = 'Generates a model, migration, controller and routes for RESTful resource'; protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
@ -36,7 +42,10 @@ class ResourceCommand extends BaseCommand {
'--belongs-to' => $this->option('belongs-to'), '--belongs-to' => $this->option('belongs-to'),
'--belongs-to-many' => $this->option('belongs-to-many'), '--belongs-to-many' => $this->option('belongs-to-many'),
'--rules' => $this->rules(), '--rules' => $this->rules(),
'--path' => 'app', '--path' => $this->option('path'),
'--force' => $this->option('force'),
'--timestamps' => $this->hasTimestamps() ? 'true' : 'false',
'--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false',
'--parsed' => true '--parsed' => true
]); ]);
@ -44,8 +53,10 @@ class ResourceCommand extends BaseCommand {
$this->call('wn:migration', [ $this->call('wn:migration', [
'table' => $tableName, 'table' => $tableName,
'--schema' => $this->schema(), '--schema' => $this->schema(),
'--keys' => $this->foreignKeys(), '--keys' => $this->migrationKeys(),
'--file' => $this->option('migration-file'), '--file' => $this->option('migration-file'),
'--force' => $this->option('force'),
'--add' => $this->option('add'),
'--parsed' => true '--parsed' => true
]); ]);
@ -53,18 +64,28 @@ class ResourceCommand extends BaseCommand {
if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){
$this->call('wn:controller:rest-actions'); $this->call('wn:controller:rest-actions');
} }
// generating the controller and routes // generating the controller and routes
$this->call('wn:controller', [ $controllerOptions = [
'model' => $modelName, 'model' => $modelName,
'--no-routes' => false '--force' => $this->option('force'),
]); '--no-routes' => false,
];
if ($this->option('laravel')) {
$controllerOptions['--laravel'] = true;
}
$this->call('wn:controller', $controllerOptions);
// generating model factory // generating model factory
// $this->call('wn:factory', [ $this->call('wn:factory', [
// 'model' => 'App\\' . $modelName, 'model' => 'App\\' . $modelName,
// '--fields' => $this->factoryFields(), '--fields' => $this->factoryFields(),
// '--parsed' => true '--force' => $this->option('force'),
'--parsed' => true
]);
// generating database seeder
// $this->call('wn:seeder', [
// 'model' => 'App\\' . $modelName
// ]); // ]);
} }
@ -74,12 +95,27 @@ class ResourceCommand extends BaseCommand {
$fields = $this->argument('fields'); $fields = $this->argument('fields');
if($this->option('parsed')){ if($this->option('parsed')){
$this->fields = $fields; $this->fields = $fields;
} else if(! $fields){ } else {
if(! $fields){
$this->fields = []; $this->fields = [];
} else { } else {
$this->fields = $this->getArgumentParser('fields') $this->fields = $this->getArgumentParser('fields')
->parse($fields); ->parse($fields);
} }
$this->fields = array_merge($this->fields, array_map(function($name) {
return [
'name' => $name,
'schema' => [
['name' => 'integer', 'args' => []],
['name' => 'unsigned', 'args' => []]
],
'rules' => 'required|numeric',
'tags' => ['fillable', 'key'],
'factory' => 'key'
];
}, $this->foreignKeys()));
}
} }
protected function fieldsHavingTag($tag) protected function fieldsHavingTag($tag)
@ -115,17 +151,31 @@ class ResourceCommand extends BaseCommand {
protected function foreignKeys() protected function foreignKeys()
{ {
return array_map(function($field){ $belongsTo = $this->option('belongs-to');
if(! $belongsTo) {
return [];
}
$relations = $this->getArgumentParser('relations')->parse($belongsTo);
return array_map(function($relation){
$name = $relation['model'] ? $relation['model'] : $relation['name'];
$index = strrpos($name, "\\");
if($index) {
$name = substr($name, $index + 1);
}
return snake_case(str_singular($name)) . '_id';
}, $relations);
}
protected function migrationKeys() {
return array_map(function($name) {
return [ return [
'name' => $field['name'], 'name' => $name,
'column' => '', 'column' => '',
'table' => '', 'table' => '',
'on_delete' => '', 'on_delete' => '',
'on_update' => '' 'on_update' => ''
]; ];
}, array_filter($this->fields, function($field){ }, $this->foreignKeys());
return in_array('key', $field['tags']);
}));
} }
protected function factoryFields() protected function factoryFields()
@ -140,4 +190,18 @@ class ResourceCommand extends BaseCommand {
})); }));
} }
protected function hasTimestamps()
{
$additionals = explode(',', $this->option('add'));
return in_array('nullableTimestamps', $additionals)
|| in_array('timestamps', $additionals)
|| in_array('timestampsTz', $additionals);
}
protected function hasSoftDeletes()
{
$additionals = explode(',', $this->option('add'));
return in_array('softDeletes', $additionals);
}
} }

View File

@ -1,12 +1,18 @@
<?php namespace Wn\Generators\Commands; <?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
class ResourcesCommand extends BaseCommand { class ResourcesCommand extends BaseCommand {
protected $signature = 'wn:resources protected $signature = 'wn:resources
{file : Path to the file containing resources declarations}'; {file : Path to the file containing resources declarations}
{--path=app : where to store the model files.}
{--force= : override the existing files}
{--laravel= : Use Laravel style route definitions}
';
protected $description = 'Generates multiple resources from a file'; protected $description = 'Generates multiple resources from a file';
@ -17,20 +23,34 @@ class ResourcesCommand extends BaseCommand {
$content = $this->fs->get($this->argument('file')); $content = $this->fs->get($this->argument('file'));
$content = Yaml::parse($content); $content = Yaml::parse($content);
$modelIndex = 0;
foreach ($content as $model => $i){ foreach ($content as $model => $i){
$i = $this->getResourceParams($model, $i); $i = $this->getResourceParams($model, $i);
$migrationName = 'Create' . ucwords(str_plural($i['name']));
$migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , 3, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table';
$this->call('wn:resource', [
$options = [
'name' => $i['name'], 'name' => $i['name'],
'fields' => $i['fields'], 'fields' => $i['fields'],
'--add' => $i['add'],
'--has-many' => $i['hasMany'], '--has-many' => $i['hasMany'],
'--has-one' => $i['hasOne'], '--has-one' => $i['hasOne'],
'--belongs-to' => $i['belongsTo'], '--belongs-to' => $i['belongsTo'],
'--belongs-to-many' => $i['belongsToMany'] '--belongs-to-many' => $i['belongsToMany'],
]); '--path' => $this->option('path'),
'--force' => $this->option('force'),
'--migration-file' => $migrationFile
];
if ($this->option('laravel')) {
$options['--laravel'] = true;
} }
$this->call('migrate'); $this->call('wn:resource', $options);
$modelIndex++;
}
// $this->call('migrate'); // actually needed for pivot seeders !
$this->pivotTables = array_map( $this->pivotTables = array_map(
'unserialize', 'unserialize',
@ -40,8 +60,15 @@ class ResourcesCommand extends BaseCommand {
foreach ($this->pivotTables as $tables) { foreach ($this->pivotTables as $tables) {
$this->call('wn:pivot-table', [ $this->call('wn:pivot-table', [
'model1' => $tables[0], 'model1' => $tables[0],
'model2' => $tables[1] 'model2' => $tables[1],
'--force' => $this->option('force')
]); ]);
// $this->call('wn:pivot-seeder', [
// 'model1' => $tables[0],
// 'model2' => $tables[1],
// '--force' => $this->option('force')
// ]);
} }
$this->call('migrate'); $this->call('migrate');
@ -51,7 +78,7 @@ class ResourcesCommand extends BaseCommand {
{ {
$i['name'] = snake_case($modelName); $i['name'] = snake_case($modelName);
foreach(['hasMany', 'hasOne', 'belongsTo', 'belongsToMany'] as $relation){ foreach(['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany'] as $relation){
if(isset($i[$relation])){ if(isset($i[$relation])){
$i[$relation] = $this->convertArray($i[$relation], ' ', ','); $i[$relation] = $this->convertArray($i[$relation], ' ', ',');
} else { } else {
@ -59,25 +86,6 @@ class ResourcesCommand extends BaseCommand {
} }
} }
if($i['belongsTo']){
$relations = $this->getArgumentParser('relations')->parse($i['belongsTo']);
foreach ($relations as $relation){
$foreignName = '';
if(! $relation['model']){
$foreignName = snake_case($relation['name']) . '_id';
} else {
$names = array_reverse(explode("\\", $relation['model']));
$foreignName = snake_case($names[0]) . '_id';
}
$i['fields'][$foreignName] = [
'schema' => 'integer',
'tags' => 'key'
];
}
}
if($i['belongsToMany']){ if($i['belongsToMany']){
$relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']); $relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']);
foreach ($relations as $relation){ foreach ($relations as $relation){
@ -111,11 +119,14 @@ class ResourcesCommand extends BaseCommand {
$name = $field['name']; $name = $field['name'];
$schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':'); $schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':');
$rules = (isset($field['rules'])) ? trim($field['rules']) : ''; $rules = (isset($field['rules'])) ? trim($field['rules']) : '';
// Replace space by comma
$rules = str_replace(' ', ',', $rules);
$tags = $this->convertArray($field['tags'], ' ', ','); $tags = $this->convertArray($field['tags'], ' ', ',');
$string = "{$name};{$schema};{$rules};{$tags}"; $string = "{$name};{$schema};{$rules};{$tags}";
if($field['factory']){ if(isset($field['factory']) && !empty($field['factory'])){
$string .= ';' . $field['factory']; $string .= ';' . $field['factory'];
} }

View File

@ -1,30 +1,67 @@
<?php namespace Wn\Generators\Commands; <?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class RouteCommand extends BaseCommand { class RouteCommand extends BaseCommand {
protected $signature = 'wn:route protected $signature = 'wn:route
{resource : Name of the resource.} {resource : Name of the resource.}
{--controller= : Name of the RESTful controller.}'; {--controller= : Name of the RESTful controller.}
{--laravel= : Use Laravel style route definitions}
';
protected $description = 'Generates RESTful routes.'; protected $description = 'Generates RESTful routes.';
public function handle() public function handle()
{ {
$resource = $this->argument('resource'); $resource = $this->argument('resource');
$laravelRoutes = $this->option('laravel');
$templateFile = 'routes';
$routesPath = 'routes/web.php';
if ($laravelRoutes) {
$templateFile = 'routes-laravel';
$routesPath = 'routes/api.php';
if (!$this->fs->isFile($routesPath)) {
if (!$this->fs->isDirectory('./routes')) {
$this->fs->makeDirectory('./routes');
}
$this->fs->put($routesPath, "
<?php
$content = $this->fs->get('./app/Http/routes.php'); use Illuminate\Http\Request;
$content .= PHP_EOL . $this->getTemplate('routes') /*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the \"api\" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request \$request) {
return \$request->user();
});
");
}
}
if (!$this->fs->isFile($routesPath)) {
$routesPath = 'app/Http/routes.php';
}
$content = $this->fs->get($routesPath);
$content .= PHP_EOL . $this->getTemplate($templateFile)
->with([ ->with([
'resource' => $resource, 'resource' => $resource,
'controller' => $this->getController() 'controller' => $this->getController()
]) ])
->get(); ->get();
$this->save($content, $routesPath, "{$resource} routes", true);
$this->save($content, './app/Http/routes.php');
$this->info("{$resource} routes generated !");
} }
protected function getController() protected function getController()

View File

@ -5,60 +5,36 @@ class SeederCommand extends BaseCommand {
protected $signature = 'wn:seeder protected $signature = 'wn:seeder
{model : full qualified name of the model.} {model : full qualified name of the model.}
{--cout=10 : number of elements to add in database.} {--count=10 : number of elements to add in database.}
{--force= : override the existing files}
'; ';
protected $description = 'Generates a model factory'; protected $description = 'Generates a seeder';
public function handle() public function handle()
{ {
$model = $this->argument('model'); $model = $this->argument('model');
$name = $this->getSeederName($model);
$file = "./database/seeds/{$name}.php";
$file = $this->getFile(); $content = $this->getTemplate('seeder')
$content = $this->fs->get($file);
$content .= $this->getTemplate('factory')
->with([ ->with([
'model' => $model, 'model' => $model,
'factory_fields' => $this->getFieldsContent() 'name' => $name,
'count' => $this->option('count')
]) ])
->get(); ->get();
$this->save($content, $file);
$this->info("{$model} factory generated !"); $this->save($content, $file, $name);
} }
protected function getFile() protected function getSeederName($name)
{ {
$file = $this->option('file'); $name = explode("\\", $name);
if(! $file){ $name = ucwords(str_plural($name[count($name) - 1]));
$file = './database/factories/ModelFactory.php'; $name = $name . 'TableSeeder';
} return $name;
return $file;
}
protected function getFieldsContent()
{
$content = [];
$fields = $this->option('fields');
if($fields){
if(! $this->option('parsed')){
$fields = $this->getArgumentParser('factory-fields')->parse($fields);
}
$template = $this->getTemplate('factory/field');
foreach($fields as $field){
$content[] = $template->with($field)->get();
}
$content = implode(PHP_EOL, $content);
} else {
$content = "\t\t// Fields here";
}
return $content;
} }
} }

View File

@ -15,9 +15,10 @@ class CommandsServiceProvider extends ServiceProvider
$this->registerResourceCommand(); $this->registerResourceCommand();
$this->registerResourcesCommand(); $this->registerResourcesCommand();
$this->registerPivotTableCommand(); $this->registerPivotTableCommand();
// $this->registerFactoryCommand(); $this->registerFactoryCommand();
// $this->registerSeedCommand(); // registerSeederCommand
// $this->registerTestCommand(); // registerPivotSeederCommand
// registerTestCommand
} }
protected function registerModelCommand(){ protected function registerModelCommand(){
@ -48,13 +49,6 @@ class CommandsServiceProvider extends ServiceProvider
$this->commands('command.wn.migration'); $this->commands('command.wn.migration');
} }
protected function registerSeedCommand(){
$this->app->singleton('command.wn.seed', function($app){
return $app['Wn\Generators\Commands\SeedCommand'];
});
$this->commands('command.wn.seed');
}
protected function registerRouteCommand(){ protected function registerRouteCommand(){
$this->app->singleton('command.wn.route', function($app){ $this->app->singleton('command.wn.route', function($app){
return $app['Wn\Generators\Commands\RouteCommand']; return $app['Wn\Generators\Commands\RouteCommand'];
@ -97,4 +91,18 @@ class CommandsServiceProvider extends ServiceProvider
$this->commands('command.wn.factory'); $this->commands('command.wn.factory');
} }
protected function registerSeederCommand(){
$this->app->singleton('command.wn.seeder', function($app){
return $app['Wn\Generators\Commands\SeederCommand'];
});
$this->commands('command.wn.seeder');
}
protected function registerPivotSeederCommand(){
$this->app->singleton('command.wn.pivot.seeder', function($app){
return $app['Wn\Generators\Commands\PivotSeederCommand'];
});
$this->commands('command.wn.pivot.seeder');
}
} }

View File

@ -1,9 +1,8 @@
<?php namespace App\Http\Controllers; <?php namespace App\Http\Controllers;
class {{name}} extends Controller { class {{name}} extends Controller {
const MODEL = "{{model}}"; const MODEL = '{{model}}';
use RESTActions; use RESTActions;

View File

@ -53,6 +53,12 @@ trait RESTActions {
protected function respond($status, $data = []) protected function respond($status, $data = [])
{ {
if($status == Response::HTTP_NO_CONTENT){
return response(null,Response::HTTP_NO_CONTENT);
}
if($status == Response::HTTP_NOT_FOUND){
return response(['message'=>'resource not found'],Response::HTTP_NOT_FOUND);
}
return response()->json($data, $status); return response()->json($data, $status);
} }

View File

@ -1,21 +0,0 @@
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
{{seeders}}
Model::reguard();
}
}

View File

@ -1 +0,0 @@
$this->call({{name}}::class);

View File

@ -12,7 +12,7 @@ class {{name}}Table extends Migration
$table->increments('id'); $table->increments('id');
{{schema}} {{schema}}
{{constraints}} {{constraints}}
$table->timestamps(); {{additionals}}
}); });
} }

View File

@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Model;
class {{name}} extends Model { class {{name}} extends Model {
protected $fillable = [{{fillable}}]; {{uses}} protected $fillable = [{{fillable}}];
protected $dates = [{{dates}}]; protected $dates = [{{dates}}];
@ -12,6 +12,6 @@ class {{name}} extends Model {
{{rules}} {{rules}}
]; ];
{{relations}} {{additional}}{{relations}}
} }

View File

@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
class {{name}} extends Seeder
{
public function run()
{
$faker = Faker::create();
$firstIds = DB::table('{{first_table}}')->lists('id');
$secondIds = DB::table('{{second_table}}')->lists('id');
for($i = 0; $i < {{count}}; $i++) {
DB::table('{{first_resource}}_{{second_resource}}')->insert([
'{{first_resource}}_id' => $faker->randomElement($firstIds),
'{{second_resource}}_id' => $faker->randomElement($secondIds)
]);
}
}
}

View File

@ -0,0 +1,8 @@
/**
* Routes for resource {{resource}}
*/
Route::get('{{resource}}', '{{controller}}@all');
Route::get('{{resource}}/{id}', '{{controller}}@get');
Route::post('{{resource}}', '{{controller}}@add');
Route::put('{{resource}}/{id}', '{{controller}}@put');
Route::delete('{{resource}}/{id}', '{{controller}}@remove');

View File

@ -1,8 +1,8 @@
/** /**
* Routes for resource {{resource}} * Routes for resource {{resource}}
*/ */
$app->get('{{resource}}', '{{controller}}@all'); $router->get('{{resource}}', '{{controller}}@all');
$app->get('{{resource}}/{id}', '{{controller}}@get'); $router->get('{{resource}}/{id}', '{{controller}}@get');
$app->post('{{resource}}', '{{controller}}@add'); $router->post('{{resource}}', '{{controller}}@add');
$app->put('{{resource}}/{id}', '{{controller}}@put'); $router->put('{{resource}}/{id}', '{{controller}}@put');
$app->delete('{{resource}}/{id}', '{{controller}}@remove'); $router->delete('{{resource}}/{id}', '{{controller}}@remove');

View File

@ -1,4 +1,9 @@
#!/usr/bin/env bash
# Runing tests for Lumen # Runing tests for Lumen
cd lumen-test cd lumen-test || return
if [ ! -f codecept.phar ]; then
wget http://codeception.com/codecept.phar wget http://codeception.com/codecept.phar
fi
php codecept.phar run php codecept.phar run