mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2025-04-20 16:12:26 +03:00
Compare commits
68 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f1debe575e | ||
|
2efa3595a5 | ||
|
c46846d978 | ||
|
8d804e09eb | ||
|
a6008f4a40 | ||
|
86493ab228 | ||
|
50c3e78483 | ||
|
ee03649641 | ||
|
8ee7bbe6b7 | ||
|
73e470ec15 | ||
|
c5218a1fd8 | ||
|
014c617cc5 | ||
|
8b6e2db315 | ||
|
a2cb5e4437 | ||
|
9a82b80cb1 | ||
|
56f0d9c0a9 | ||
|
573d55c9b2 | ||
|
a951151697 | ||
|
5e2c21855e | ||
|
2817f3591b | ||
|
a2cf22d426 | ||
|
6e00a91eea | ||
|
afa5bf1f0c | ||
|
982dee15fc | ||
|
434e7f6b2c | ||
|
dafa7f2f22 | ||
|
874e793594 | ||
|
7d42825426 | ||
|
7f1b5407ee | ||
|
cc39d720c4 | ||
|
9ab561df2f | ||
|
5662a5d4bb | ||
|
b22b59ab5d | ||
|
5cf6f6ed9c | ||
|
8e57d36894 | ||
|
5ad49aa58a | ||
|
057199cb8b | ||
|
27dc508bca | ||
|
de26849f18 | ||
|
9ba5b5f7fe | ||
|
cfe5b2f69b | ||
|
482cc3f8c4 | ||
|
55fcf27362 | ||
|
93856362b7 | ||
|
6e7d3fbf95 | ||
|
a9c12e9fa0 | ||
|
17bc595db9 | ||
|
942b8fefb4 | ||
|
b2510a01e4 | ||
|
c0daa0c97b | ||
|
3eae8983c9 | ||
|
6094a546fc | ||
|
024b2e33d0 | ||
|
33d7a151ae | ||
|
b6d47df699 | ||
|
5f8f2f2888 | ||
|
d149e7532e | ||
|
5605377f86 | ||
|
8af58ea50a | ||
|
a52c059050 | ||
|
a33ffc7742 | ||
|
7be47337d8 | ||
|
b743670470 | ||
|
714d11efd8 | ||
|
9b1c38b58d | ||
|
473e51f8d4 | ||
|
34d8828e5f | ||
|
f954b5481e |
14
.editorconfig
Normal file
14
.editorconfig
Normal 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
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -3,3 +3,9 @@
|
|||||||
*.sublime-*
|
*.sublime-*
|
||||||
|
|
||||||
tests/_output/*
|
tests/_output/*
|
||||||
|
|
||||||
|
lumen-test/app
|
||||||
|
lumen-test/database
|
||||||
|
lumen-test/tests/tmp
|
||||||
|
|
||||||
|
.idea
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Amine Ben hammou <webneat@gmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
145
README.md
145
README.md
@ -1,9 +1,11 @@
|
|||||||
# Lumen generators
|
# Lumen generators
|
||||||
|
|
||||||
[](https://travis-ci.org/webNeat/lumen-generators)
|
[](https://travis-ci.org/webNeat/lumen-generators)
|
||||||
[](http://opensource.org/licenses/MIT)
|
[](https://scrutinizer-ci.com/g/webNeat/lumen-generators/?branch=master)
|
||||||
|
[](https://insight.sensiolabs.com/projects/838624c3-208d-4ba5-84aa-3afc76b093bb)
|
||||||
|
[](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,18 +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.
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Pull requests are welcome :D
|
Pull requests are welcome :D
|
||||||
|
@ -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,10 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"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"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
1885
composer.lock
generated
1885
composer.lock
generated
File diff suppressed because it is too large
Load Diff
8
formats/factory-fields.json
Normal file
8
formats/factory-fields.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"type": "array",
|
||||||
|
"fields": {
|
||||||
|
"type": "object",
|
||||||
|
"separator": ":",
|
||||||
|
"fields": ["name","type"]
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rules",
|
"rules",
|
||||||
"tags[]"
|
"tags[]",
|
||||||
|
{
|
||||||
|
"name": "factory",
|
||||||
|
"type": "string",
|
||||||
|
"default": false
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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
|
5
lumen-test/.gitignore
vendored
5
lumen-test/.gitignore
vendored
@ -1,6 +1,11 @@
|
|||||||
/vendor
|
/vendor
|
||||||
.env
|
.env
|
||||||
|
codecept.phar
|
||||||
|
|
||||||
tests/_output/*
|
tests/_output/*
|
||||||
|
|
||||||
composer.lock
|
composer.lock
|
||||||
|
tests/_output/*
|
||||||
|
|
||||||
|
codecept.phar
|
||||||
|
|
||||||
|
@ -8,3 +8,4 @@ class Controller extends BaseController
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
51
lumen-test/clean.sh
Executable 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
|
@ -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:
|
||||||
|
@ -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/"
|
||||||
|
@ -14,7 +14,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
Model::unguard();
|
Model::unguard();
|
||||||
|
|
||||||
// $this->call('UserTableSeeder');
|
// $this->call(ProjectsTableSeeder::class);
|
||||||
|
|
||||||
Model::reguard();
|
Model::reguard();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testBasicExample()
|
|
||||||
{
|
|
||||||
$this->visit('/')
|
|
||||||
->see('Lumen.');
|
|
||||||
}
|
|
||||||
}
|
|
@ -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';
|
|
||||||
}
|
|
||||||
}
|
|
26
lumen-test/tests/_data/ResourcesTest.yml
Normal file
26
lumen-test/tests/_data/ResourcesTest.yml
Normal 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
|
@ -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)
|
||||||
*/
|
*/
|
||||||
|
@ -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)
|
||||||
*/
|
*/
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
*/
|
*/
|
||||||
|
@ -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) {
|
||||||
|
@ -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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
@ -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";
|
||||||
|
@ -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');
|
||||||
|
68
lumen-test/tests/acceptance/FactoryCommandCept.php
Normal file
68
lumen-test/tests/acceptance/FactoryCommandCept.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
$I = new AcceptanceTester($scenario);
|
||||||
|
|
||||||
|
$I->wantTo('generate model factories without fields');
|
||||||
|
$I->runShellCommand('php artisan wn:factory "App\Task"');
|
||||||
|
$I->seeInShellOutput('App\Task factory generated');
|
||||||
|
$I->openFile('./database/factories/ModelFactory.php');
|
||||||
|
$I->seeInThisFile('
|
||||||
|
$factory->define(App\Task::class, function ($faker) {
|
||||||
|
return [
|
||||||
|
// Fields here
|
||||||
|
];
|
||||||
|
});');
|
||||||
|
$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->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->seeInShellOutput('App\Task factory generated');
|
||||||
|
$I->openFile('./database/factories/ModelFactory.php');
|
||||||
|
$I->seeInThisFile(
|
||||||
|
" 'title' => \$faker->sentence(3)," . PHP_EOL .
|
||||||
|
" 'description' => \$faker->paragraph(3)," . PHP_EOL .
|
||||||
|
" 'due' => \$faker->date," . PHP_EOL .
|
||||||
|
" 'hidden' => \$faker->boolean,"
|
||||||
|
);
|
||||||
|
$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),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
");
|
@ -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');
|
@ -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');
|
||||||
|
29
lumen-test/tests/acceptance/PivotSeederCommandCept.php
Normal file
29
lumen-test/tests/acceptance/PivotSeederCommandCept.php
Normal 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');
|
@ -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');
|
||||||
|
@ -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 descr;text:nullable;;fillable project_id;integer;required;key,fillable due;timestamp;;fillable,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');
|
||||||
|
|
||||||
@ -103,3 +108,53 @@ $app->get("/", function () use ($app) {
|
|||||||
return $app->welcome();
|
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),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
");
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
136
lumen-test/tests/acceptance/ResourcesCommandCept.php
Normal file
136
lumen-test/tests/acceptance/ResourcesCommandCept.php
Normal 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');
|
124
lumen-test/tests/acceptance/ResourcesWithLaravelRoutesCept.php
Normal file
124
lumen-test/tests/acceptance/ResourcesWithLaravelRoutesCept.php
Normal 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');
|
@ -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');
|
||||||
|
34
lumen-test/tests/acceptance/SeederCommandCept.php
Normal file
34
lumen-test/tests/acceptance/SeederCommandCept.php
Normal 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');
|
@ -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];
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
65
src/Commands/FactoryCommand.php
Normal file
65
src/Commands/FactoryCommand.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php namespace Wn\Generators\Commands;
|
||||||
|
|
||||||
|
|
||||||
|
class FactoryCommand extends BaseCommand {
|
||||||
|
|
||||||
|
protected $signature = 'wn:factory
|
||||||
|
{model : full qualified name of the model.}
|
||||||
|
{--fields= : the fields to generate.}
|
||||||
|
{--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}
|
||||||
|
{--force= : override the existing files}
|
||||||
|
';
|
||||||
|
|
||||||
|
protected $description = 'Generates a model factory';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$model = $this->argument('model');
|
||||||
|
|
||||||
|
$file = $this->getFile();
|
||||||
|
|
||||||
|
$content = $this->fs->get($file);
|
||||||
|
|
||||||
|
$content .= $this->getTemplate('factory')
|
||||||
|
->with([
|
||||||
|
'model' => $model,
|
||||||
|
'factory_fields' => $this->getFieldsContent()
|
||||||
|
])
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$this->save($content, $file, "{$model} factory", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getFile()
|
||||||
|
{
|
||||||
|
$file = $this->option('file');
|
||||||
|
if(! $file){
|
||||||
|
$file = './database/factories/ModelFactory.php';
|
||||||
|
}
|
||||||
|
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 = " // Fields here";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
: '';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
58
src/Commands/PivotSeederCommand.php
Normal file
58
src/Commands/PivotSeederCommand.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,22 +53,41 @@ 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
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// generation REST actions trait if doesn't exist
|
// generating REST actions trait if doesn't exist
|
||||||
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
|
||||||
|
$this->call('wn:factory', [
|
||||||
|
'model' => 'App\\' . $modelName,
|
||||||
|
'--fields' => $this->factoryFields(),
|
||||||
|
'--force' => $this->option('force'),
|
||||||
|
'--parsed' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// generating database seeder
|
||||||
|
// $this->call('wn:seeder', [
|
||||||
|
// 'model' => 'App\\' . $modelName
|
||||||
|
// ]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseFields()
|
protected function parseFields()
|
||||||
@ -67,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)
|
||||||
@ -108,17 +151,57 @@ 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' => ''
|
||||||
];
|
];
|
||||||
|
}, $this->foreignKeys());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function factoryFields()
|
||||||
|
{
|
||||||
|
return array_map(function($field){
|
||||||
|
return [
|
||||||
|
'name' => $field['name'],
|
||||||
|
'type' => $field['factory']
|
||||||
|
];
|
||||||
}, array_filter($this->fields, function($field){
|
}, array_filter($this->fields, function($field){
|
||||||
return in_array('key', $field['tags']);
|
return isset($field['factory']) && $field['factory'];
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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,39 +23,62 @@ 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('wn:resource', $options);
|
||||||
|
$modelIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $this->call('migrate'); // actually needed for pivot seeders !
|
||||||
|
|
||||||
$this->pivotTables = array_map(
|
$this->pivotTables = array_map(
|
||||||
'unserialize',
|
'unserialize',
|
||||||
array_unique(array_map('serialize', $this->pivotTables))
|
array_unique(array_map('serialize', $this->pivotTables))
|
||||||
);
|
);
|
||||||
|
|
||||||
dd($this->pivotTables);
|
|
||||||
|
|
||||||
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getResourceParams($modelName, $i)
|
protected function getResourceParams($modelName, $i)
|
||||||
{
|
{
|
||||||
$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 {
|
||||||
@ -57,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){
|
||||||
@ -109,9 +119,18 @@ 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'], ' ', ',');
|
||||||
|
|
||||||
return "{$name};{$schema};{$rules};{$tags}";
|
$string = "{$name};{$schema};{$rules};{$tags}";
|
||||||
|
|
||||||
|
if(isset($field['factory']) && !empty($field['factory'])){
|
||||||
|
$string .= ';' . $field['factory'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function convertArray($list, $old, $new)
|
protected function convertArray($list, $old, $new)
|
||||||
|
@ -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()
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Comming Soon
|
|
||||||
*/
|
|
40
src/Commands/SeederCommand.php
Normal file
40
src/Commands/SeederCommand.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php namespace Wn\Generators\Commands;
|
||||||
|
|
||||||
|
|
||||||
|
class SeederCommand extends BaseCommand {
|
||||||
|
|
||||||
|
protected $signature = 'wn:seeder
|
||||||
|
{model : full qualified name of the model.}
|
||||||
|
{--count=10 : number of elements to add in database.}
|
||||||
|
{--force= : override the existing files}
|
||||||
|
';
|
||||||
|
|
||||||
|
protected $description = 'Generates a seeder';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$model = $this->argument('model');
|
||||||
|
$name = $this->getSeederName($model);
|
||||||
|
$file = "./database/seeds/{$name}.php";
|
||||||
|
|
||||||
|
$content = $this->getTemplate('seeder')
|
||||||
|
->with([
|
||||||
|
'model' => $model,
|
||||||
|
'name' => $name,
|
||||||
|
'count' => $this->option('count')
|
||||||
|
])
|
||||||
|
->get();
|
||||||
|
|
||||||
|
|
||||||
|
$this->save($content, $file, $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getSeederName($name)
|
||||||
|
{
|
||||||
|
$name = explode("\\", $name);
|
||||||
|
$name = ucwords(str_plural($name[count($name) - 1]));
|
||||||
|
$name = $name . 'TableSeeder';
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,8 +15,10 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
$this->registerResourceCommand();
|
$this->registerResourceCommand();
|
||||||
$this->registerResourcesCommand();
|
$this->registerResourcesCommand();
|
||||||
$this->registerPivotTableCommand();
|
$this->registerPivotTableCommand();
|
||||||
// $this->registerSeedCommand();
|
$this->registerFactoryCommand();
|
||||||
// $this->registerTestCommand();
|
// registerSeederCommand
|
||||||
|
// registerPivotSeederCommand
|
||||||
|
// registerTestCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerModelCommand(){
|
protected function registerModelCommand(){
|
||||||
@ -24,7 +26,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\ModelCommand'];
|
return $app['Wn\Generators\Commands\ModelCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.model');
|
$this->commands('command.wn.model');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerControllerRestActionsCommand(){
|
protected function registerControllerRestActionsCommand(){
|
||||||
@ -32,7 +33,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\ControllerRestActionsCommand'];
|
return $app['Wn\Generators\Commands\ControllerRestActionsCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.controller.rest-actions');
|
$this->commands('command.wn.controller.rest-actions');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerControllerCommand(){
|
protected function registerControllerCommand(){
|
||||||
@ -40,7 +40,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\ControllerCommand'];
|
return $app['Wn\Generators\Commands\ControllerCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.controller');
|
$this->commands('command.wn.controller');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerMigrationCommand(){
|
protected function registerMigrationCommand(){
|
||||||
@ -48,15 +47,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\MigrationCommand'];
|
return $app['Wn\Generators\Commands\MigrationCommand'];
|
||||||
});
|
});
|
||||||
$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(){
|
||||||
@ -64,7 +54,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\RouteCommand'];
|
return $app['Wn\Generators\Commands\RouteCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.route');
|
$this->commands('command.wn.route');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerTestCommand(){
|
protected function registerTestCommand(){
|
||||||
@ -72,7 +61,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\TestCommand'];
|
return $app['Wn\Generators\Commands\TestCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.test');
|
$this->commands('command.wn.test');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerResourceCommand(){
|
protected function registerResourceCommand(){
|
||||||
@ -80,7 +68,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\ResourceCommand'];
|
return $app['Wn\Generators\Commands\ResourceCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.resource');
|
$this->commands('command.wn.resource');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerResourcesCommand(){
|
protected function registerResourcesCommand(){
|
||||||
@ -88,7 +75,6 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\ResourcesCommand'];
|
return $app['Wn\Generators\Commands\ResourcesCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.resources');
|
$this->commands('command.wn.resources');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerPivotTableCommand(){
|
protected function registerPivotTableCommand(){
|
||||||
@ -96,7 +82,27 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
return $app['Wn\Generators\Commands\PivotTableCommand'];
|
return $app['Wn\Generators\Commands\PivotTableCommand'];
|
||||||
});
|
});
|
||||||
$this->commands('command.wn.pivot-table');
|
$this->commands('command.wn.pivot-table');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerFactoryCommand(){
|
||||||
|
$this->app->singleton('command.wn.factory', function($app){
|
||||||
|
return $app['Wn\Generators\Commands\FactoryCommand'];
|
||||||
|
});
|
||||||
|
$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');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -1,24 +1,15 @@
|
|||||||
<?php namespace App\Http\Controllers;
|
<?php namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
trait RESTActions {
|
trait RESTActions {
|
||||||
|
|
||||||
protected $statusCodes = [
|
|
||||||
'done' => 200,
|
|
||||||
'created' => 201,
|
|
||||||
'removed' => 204,
|
|
||||||
'not_valid' => 400,
|
|
||||||
'not_found' => 404,
|
|
||||||
'conflict' => 409,
|
|
||||||
'permissions' => 401
|
|
||||||
];
|
|
||||||
|
|
||||||
public function all()
|
public function all()
|
||||||
{
|
{
|
||||||
$m = self::MODEL;
|
$m = self::MODEL;
|
||||||
return $this->respond('done', $m::all());
|
return $this->respond(Response::HTTP_OK, $m::all());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($id)
|
public function get($id)
|
||||||
@ -26,16 +17,16 @@ trait RESTActions {
|
|||||||
$m = self::MODEL;
|
$m = self::MODEL;
|
||||||
$model = $m::find($id);
|
$model = $m::find($id);
|
||||||
if(is_null($model)){
|
if(is_null($model)){
|
||||||
return $this->respond('not_found');
|
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
return $this->respond('done', $model);
|
return $this->respond(Response::HTTP_OK, $model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add(Request $request)
|
public function add(Request $request)
|
||||||
{
|
{
|
||||||
$m = self::MODEL;
|
$m = self::MODEL;
|
||||||
$this->validate($request, $m::$rules);
|
$this->validate($request, $m::$rules);
|
||||||
return $this->respond('created', $m::create($request->all()));
|
return $this->respond(Response::HTTP_CREATED, $m::create($request->all()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function put(Request $request, $id)
|
public function put(Request $request, $id)
|
||||||
@ -44,25 +35,31 @@ trait RESTActions {
|
|||||||
$this->validate($request, $m::$rules);
|
$this->validate($request, $m::$rules);
|
||||||
$model = $m::find($id);
|
$model = $m::find($id);
|
||||||
if(is_null($model)){
|
if(is_null($model)){
|
||||||
return $this->respond('not_found');
|
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
$model->update($request->all());
|
$model->update($request->all());
|
||||||
return $this->respond('done', $model);
|
return $this->respond(Response::HTTP_OK, $model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove($id)
|
public function remove($id)
|
||||||
{
|
{
|
||||||
$m = self::MODEL;
|
$m = self::MODEL;
|
||||||
if(is_null($m::find($id))){
|
if(is_null($m::find($id))){
|
||||||
return $this->respond('not_found');
|
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
$m::destroy($id);
|
$m::destroy($id);
|
||||||
return $this->respond('removed');
|
return $this->respond(Response::HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function respond($status, $data = [])
|
protected function respond($status, $data = [])
|
||||||
{
|
{
|
||||||
return response()->json($data, $this->statusCodes[$status]);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
9
templates/factory.wnt
Normal file
9
templates/factory.wnt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Factory definition for model {{model}}.
|
||||||
|
*/
|
||||||
|
$factory->define({{model}}::class, function ($faker) {
|
||||||
|
return [
|
||||||
|
{{factory_fields}}
|
||||||
|
];
|
||||||
|
});
|
1
templates/factory/field.wnt
Normal file
1
templates/factory/field.wnt
Normal file
@ -0,0 +1 @@
|
|||||||
|
'{{name}}' => $faker->{{type}},
|
@ -12,7 +12,7 @@ class {{name}}Table extends Migration
|
|||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
{{schema}}
|
{{schema}}
|
||||||
{{constraints}}
|
{{constraints}}
|
||||||
$table->timestamps();
|
{{additionals}}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
22
templates/pivot-seeder.wnt
Normal file
22
templates/pivot-seeder.wnt
Normal 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)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
templates/routes-laravel.wnt
Normal file
8
templates/routes-laravel.wnt
Normal 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');
|
@ -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');
|
||||||
|
11
templates/seeder.wnt
Normal file
11
templates/seeder.wnt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class {{name}} extends Seeder
|
||||||
|
{
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
factory({{model}}::class, {{count}})->create();
|
||||||
|
}
|
||||||
|
}
|
7
test.sh
7
test.sh
@ -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
|
Loading…
x
Reference in New Issue
Block a user