Compare commits

...

37 Commits

Author SHA1 Message Date
Arthur
f1debe575e
Package name update
Package name update
2020-04-06 20:12:04 +03:00
Arthur
2efa3595a5
Update README.md 2020-04-06 20:10:23 +03:00
Arthur
c46846d978
Update dependencies
Update dependencies to work with Lumen v.6
2020-04-06 20:06:58 +03:00
Amine Ben hammou
8d804e09eb
Merge pull request #50 from davidporos92/hotfix/migration-generator
Delete old migration file if exists when creating a new one
2018-06-09 05:30:26 +00:00
Amine Ben hammou
a6008f4a40 Merge pull request #48 from AfzalH/master
Some fixes for latest lumen. Also added customized response for NOT_FOUND and NO_CONTENT response
2017-10-23 00:12:29 +02:00
Pörös Dávid
86493ab228 delete old migration file
refs #44
2017-10-21 01:19:28 +02:00
Afzal Hossain
50c3e78483 Better control over not_found and no_content response 2017-10-20 19:04:20 +06:00
Afzal Hossain
ee03649641 Single quote around model to avoid IDE warning 2017-10-20 19:02:37 +06:00
Afzal Hossain
8ee7bbe6b7 $app->get() no longer works. Replaced. 2017-10-20 19:01:22 +06:00
Amine Ben hammou
73e470ec15 Merge pull request #40 from josiahdahl/laravel-routes
Enable Creating Laravel Style Routes
2017-08-09 00:57:18 +02:00
Josiah Dahl
c5218a1fd8 Merge branch 'master' into laravel-routes 2017-08-08 14:10:20 -07:00
Amine Ben hammou
014c617cc5 Merge pull request #39 from josiahdahl/sequential-model-filenames
Sequential Filenames with Resources Command
2017-08-08 21:52:03 +02:00
Josiah Dahl
8b6e2db315 Added database for testing 2017-08-07 12:28:22 -07:00
Josiah Dahl
a2cb5e4437 Add database creation for testing 2017-08-07 12:23:08 -07:00
Josiah Dahl
9a82b80cb1 fix test bug 2017-08-07 12:12:39 -07:00
Josiah Dahl
56f0d9c0a9 Ensure commands work and tests pass 2017-08-07 11:51:53 -07:00
Josiah Dahl
573d55c9b2 updated README 2017-08-07 11:51:43 -07:00
Josiah Dahl
a951151697 Finalize testing 2017-08-07 11:02:36 -07:00
Josiah Dahl
5e2c21855e Tests are failing only for the new route options 2017-08-06 23:06:04 -07:00
Josiah Dahl
2817f3591b Add resources data 2017-08-06 23:01:36 -07:00
Josiah Dahl
a2cf22d426 Added Laravel Routes
- New template
- Command updates
2017-08-06 20:54:39 -07:00
Josiah Dahl
6e00a91eea Fixed string padding 2017-08-06 15:56:01 -07:00
Josiah Dahl
afa5bf1f0c Pad the model index to 3 characters 2017-08-06 09:44:50 -07:00
Josiah Dahl
982dee15fc Possible codeception updates 2017-08-06 09:37:25 -07:00
Josiah Dahl
434e7f6b2c Testing Resources Command
Finialized testing the changes to the resources command.
2017-08-06 09:36:57 -07:00
Amine Ben hammou
dafa7f2f22 Release 1.3.3 2017-05-08 02:22:45 +02:00
Amine Ben hammou
874e793594 Merge pull request #36 from StephaneBour/master
fix path option for wn:ressources
2017-05-08 02:15:09 +02:00
Stéphane
7d42825426
rollback: remove path (I just understood that it was only for the model...) 2017-05-07 21:58:49 +02:00
Stéphane
7f1b5407ee
chore: composer update 2017-05-07 21:28:18 +02:00
Stéphane
cc39d720c4
fix: rules not support space
replace space by comma (i think the bug is same for #33)
2017-05-07 21:27:58 +02:00
Stéphane
9ab561df2f
fix: change version of codeception 2017-05-07 20:24:40 +02:00
Stéphane
5662a5d4bb
fix: add path if option is passed 2017-05-07 20:00:32 +02:00
Stéphane
b22b59ab5d
perf: detect if codecept exist 2017-05-07 19:40:18 +02:00
Amine Ben hammou
5cf6f6ed9c Model softDeletes trait fixed 2017-02-04 21:55:44 +00:00
Amine Ben hammou
8e57d36894 bug fixed: soft deletes missing in the model 2017-01-28 14:35:11 +00:00
Amine Ben hammou
5ad49aa58a release 1.3.1 2017-01-20 19:20:55 +00:00
Amine Ben hammou
057199cb8b fixed the duplicate column for the foriegn key bug 2017-01-20 19:01:25 +00:00
30 changed files with 1005 additions and 1844 deletions

2
.gitignore vendored
View File

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

View File

@ -5,7 +5,7 @@
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/838624c3-208d-4ba5-84aa-3afc76b093bb/mini.png)](https://insight.sensiolabs.com/projects/838624c3-208d-4ba5-84aa-3afc76b093bb)
[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://github.com/webNeat/lumen-generators/blob/master/LICENSE)
A collection of generators for [Lumen](http://lumen.laravel.com) and [Laravel 5](http://laravel.com/).
A collection of generators for [Lumen](http://lumen.laravel.com) and [Laravel 6](http://laravel.com/).
## Contents
@ -259,10 +259,10 @@ 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:
```
wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--timestamps=false] [--path=...] [--force=true]
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.
`php artisan wn:model Task` generates the following:
@ -361,6 +361,8 @@ 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:
```
@ -507,7 +509,9 @@ The second command is `wn:controller` which actually generates the controller. T
- **--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.
- **--force**: tells the generator to override the existing file.
- **--laravel**: create Laravel style routes
`php artisan wn:controller Task --no-routes` gives:
@ -537,6 +541,9 @@ The `wn:route` command is used to generate RESTfull routes for a controller. It
- **--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
@ -547,6 +554,17 @@ $app->put('project-type/{id}', 'ProjectTypesController@put');
$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
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]`
@ -579,6 +597,9 @@ The `wn:resource` command makes it very easy to generate a RESTful resource. It
- **--force**: tells the generator to override the existing file.
- **--laravel**: create Laravel style routes
### 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
@ -593,6 +614,9 @@ The file given to the command should be a valid YAML file ( for the moment, supp
- **--path**: Defines where to store the model files as well as their namespace.
- **--laravel**: create Laravel style routes
```yaml
---
Store:
@ -638,6 +662,24 @@ To test the generators, I included a fresh lumen installation under the folder `
- **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**

View File

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

1917
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,11 @@
/vendor
.env
codecept.phar
tests/_output/*
composer.lock
tests/_output/*
tests/_output/*
codecept.phar

View File

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

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

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

View File

@ -5,6 +5,7 @@ paths:
data: tests/_data
support: tests/_support
envs: tests/_envs
helpers: nil
settings:
bootstrap: _bootstrap.php
colors: false

View File

@ -13,7 +13,7 @@
"phpunit/phpunit": "~4.0",
"fzaninotto/faker": "~1.0",
"phpspec/phpspec": "2.0.0",
"codeception/codeception": "2.0.0"
"codeception/codeception": "^2.2"
},
"autoload": {
"psr-4": {

View File

@ -1,23 +0,0 @@
---
Post:
belongsToMany: tags
add: timestamps softDeletes
fields:
title:
schema: string
rules: required
tags: fillable
content:
schema: text nullable
tags: fillable
published_at:
schema: date
rules: date
tags: date fillable
Tag:
belongsToMany: posts
fields:
name:
schema: string unique
rules: required
tags: fillable

View File

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

View File

@ -1,4 +1,4 @@
<?php //[STAMP] 6172d62f52ee53bf8d6f975a52df4f0d
<?php //[STAMP] d6606f78456705b0875c6b8343fc6a4a
namespace _generated;
// This class was automatically generated by build task
@ -17,6 +17,22 @@ trait AcceptanceTesterActions
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.
*
@ -95,7 +111,7 @@ trait AcceptanceTesterActions
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @param $regex
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Cli::seeShellOutputMatches()
*/
@ -105,7 +121,7 @@ trait AcceptanceTesterActions
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @param $regex
* @see \Codeception\Module\Cli::seeShellOutputMatches()
*/
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.
*
* Enters a directory In local filesystem.
* Project root directory is used by default
*
* @param $path
* @param string $path
* @see \Codeception\Module\Filesystem::amInPath()
*/
public function amInPath($path) {
@ -141,7 +227,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @see \Codeception\Module\Filesystem::openFile()
*/
public function openFile($filename) {
@ -160,7 +246,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @see \Codeception\Module\Filesystem::deleteFile()
*/
public function deleteFile($filename) {
@ -179,7 +265,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $dirname
* @param string $dirname
* @see \Codeception\Module\Filesystem::deleteDir()
*/
public function deleteDir($dirname) {
@ -198,8 +284,8 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $src
* @param $dst
* @param string $src
* @param string $dst
* @see \Codeception\Module\Filesystem::copyDir()
*/
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
* @see \Codeception\Module\Filesystem::seeInThisFile()
*/
@ -242,7 +328,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* @see \Codeception\Module\Filesystem::seeInThisFile()
*/
public function seeInThisFile($text) {
@ -298,7 +384,7 @@ trait AcceptanceTesterActions
*
* Checks that contents of currently opened file matches $regex
*
* @param $regex
* @param string $regex
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
*/
@ -310,7 +396,7 @@ trait AcceptanceTesterActions
*
* Checks that contents of currently opened file matches $regex
*
* @param $regex
* @param string $regex
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
*/
public function seeThisFileMatches($regex) {
@ -333,7 +419,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeFileContentsEqual()
*/
@ -355,7 +441,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* @see \Codeception\Module\Filesystem::seeFileContentsEqual()
*/
public function seeFileContentsEqual($text) {
@ -375,7 +461,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::dontSeeInThisFile()
*/
@ -394,7 +480,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* @see \Codeception\Module\Filesystem::dontSeeInThisFile()
*/
public function dontSeeInThisFile($text) {
@ -425,7 +511,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @param string $path
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeFileFound()
@ -445,7 +531,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @param string $path
* @see \Codeception\Module\Filesystem::seeFileFound()
*/
@ -459,7 +545,7 @@ trait AcceptanceTesterActions
*
* Checks if file does not exist in path
*
* @param $filename
* @param string $filename
* @param string $path
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::dontSeeFileFound()
@ -472,7 +558,7 @@ trait AcceptanceTesterActions
*
* Checks if file does not exist in path
*
* @param $filename
* @param string $filename
* @param string $path
* @see \Codeception\Module\Filesystem::dontSeeFileFound()
*/
@ -492,7 +578,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $dirname
* @param string $dirname
* @see \Codeception\Module\Filesystem::cleanDir()
*/
public function cleanDir($dirname) {
@ -505,8 +591,8 @@ trait AcceptanceTesterActions
*
* Saves contents to file
*
* @param $filename
* @param $contents
* @param string $filename
* @param string $contents
* @see \Codeception\Module\Filesystem::writeToFile()
*/
public function writeToFile($filename, $contents) {

View File

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

View File

@ -1,4 +1,4 @@
<?php //[STAMP] afa4f0350422fae145b4236dce66191a
<?php //[STAMP] 1467e0d5027bbc2413077351642a21f3
namespace _generated;
// This class was automatically generated by build task
@ -19,14 +19,29 @@ trait UnitTesterActions
/**
* [!] 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 $actual
* @param string $message
* @param float $delta
* @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()));
}
@ -34,14 +49,29 @@ trait UnitTesterActions
/**
* [!] 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 $actual
* @param string $message
* @param float $delta
* @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()));
}
@ -54,7 +84,6 @@ trait UnitTesterActions
* @param $expected
* @param $actual
* @param string $message
* @return mixed|void
* @see \Codeception\Module\Asserts::assertSame()
*/
public function assertSame($expected, $actual, $message = null) {
@ -197,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.
*
@ -373,6 +432,22 @@ trait UnitTesterActions
}
/**
* [!] 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.
*

View File

@ -106,3 +106,29 @@ $I->seeInThisFile(
);
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with softDeletes');
$I->runShellCommand('php artisan wn:model TestingModel --soft-deletes=true --path=tests/tmp --force=true');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
$I->seeFileContentsEqual('<?php namespace Tests\Tmp;
use Illuminate\Database\Eloquent\Model;
class TestingModel extends Model {
use \Illuminate\Database\Eloquent\SoftDeletes;
protected $fillable = [];
protected $dates = [];
public static $rules = [
// Validation rules
];
// Relationships
}
');
$I->deleteFile('./tests/tmp/TestingModel.php');

View File

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

View File

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

View File

@ -62,7 +62,9 @@ $app->get("/", function () use ($app) {
$I->wantTo('run wn:routes in Lumen 5.3+');
mkdir('./routes');
if(!file_exists('./routes')) {
mkdir('./routes');
}
$I->writeToFile('./routes/web.php', '<?php
/*

View File

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

View File

@ -3,7 +3,7 @@
class MigrationCommand extends BaseCommand {
protected $signature = 'wn:migration
protected $signature = 'wn:migration
{table : The table name.}
{--schema= : the schema.}
{--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.}
@ -12,15 +12,16 @@ class MigrationCommand extends BaseCommand {
{--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.}
// The action is only create for the moment
// {action : One of create, add, remove or drop options.}
// The action is only create for the moment
protected $description = 'Generates a migration to create a table with schema';
protected $description = 'Generates a migration to create a table with schema';
public function handle()
{
$table = $this->argument('table');
$name = 'Create' . ucwords(camel_case($table));
$snakeName = snake_case($name);
$content = $this->getTemplate('migration')
->with([
@ -34,12 +35,26 @@ class MigrationCommand extends BaseCommand {
$file = $this->option('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", "{$table} migration");
}
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()
{
$schema = $this->option('schema');
@ -127,20 +142,20 @@ class MigrationCommand extends BaseCommand {
if($key['on_delete']){
$constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint')
->with([
'event' => 'Delete',
'action' => $key['on_delete']
])
->get();
->with([
'event' => 'Delete',
'action' => $key['on_delete']
])
->get();
}
if($key['on_update']){
$constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint')
->with([
'event' => 'Update',
'action' => $key['on_update']
])
->get();
->with([
'event' => 'Update',
'action' => $key['on_update']
])
->get();
}
return $constraint . ';';

View File

@ -14,6 +14,7 @@ class ModelCommand extends BaseCommand {
{--rules= : fields validation rules.}
{--timestamps=true : enables timestamps on the model.}
{--path=app : where to store the model php file.}
{--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}
';
@ -33,7 +34,8 @@ class ModelCommand extends BaseCommand {
'dates' => $this->getAsArrayFields('dates'),
'relations' => $this->getRelations(),
'rules' => $this->getRules(),
'additional' => $this->getAdditional()
'additional' => $this->getAdditional(),
'uses' => $this->getUses()
])
->get();
@ -123,4 +125,11 @@ class ModelCommand extends BaseCommand {
: '';
}
protected function getUses()
{
return $this->option('soft-deletes') == 'true'
? ' use \Illuminate\Database\Eloquent\SoftDeletes;' . PHP_EOL . PHP_EOL
: '';
}
}

View File

@ -1,6 +1,8 @@
<?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class ResourceCommand extends BaseCommand {
protected $signature = 'wn:resource
@ -15,6 +17,7 @@ class ResourceCommand extends BaseCommand {
{--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}
{--force= : override the existing files}
{--laravel= : Use Laravel style route definitions}
';
protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
@ -42,6 +45,7 @@ class ResourceCommand extends BaseCommand {
'--path' => $this->option('path'),
'--force' => $this->option('force'),
'--timestamps' => $this->hasTimestamps() ? 'true' : 'false',
'--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false',
'--parsed' => true
]);
@ -60,13 +64,16 @@ class ResourceCommand extends BaseCommand {
if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){
$this->call('wn:controller:rest-actions');
}
// generating the controller and routes
$this->call('wn:controller', [
$controllerOptions = [
'model' => $modelName,
'--force' => $this->option('force'),
'--no-routes' => false
]);
'--no-routes' => false,
];
if ($this->option('laravel')) {
$controllerOptions['--laravel'] = true;
}
$this->call('wn:controller', $controllerOptions);
// generating model factory
$this->call('wn:factory', [
@ -191,4 +198,10 @@ class ResourceCommand extends BaseCommand {
|| in_array('timestampsTz', $additionals);
}
protected function hasSoftDeletes()
{
$additionals = explode(',', $this->option('add'));
return in_array('softDeletes', $additionals);
}
}

View File

@ -1,5 +1,6 @@
<?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
@ -9,6 +10,8 @@ class ResourcesCommand extends BaseCommand {
{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';
@ -20,10 +23,14 @@ class ResourcesCommand extends BaseCommand {
$content = $this->fs->get($this->argument('file'));
$content = Yaml::parse($content);
$modelIndex = 0;
foreach ($content as $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'],
'fields' => $i['fields'],
'--add' => $i['add'],
@ -32,11 +39,18 @@ class ResourcesCommand extends BaseCommand {
'--belongs-to' => $i['belongsTo'],
'--belongs-to-many' => $i['belongsToMany'],
'--path' => $this->option('path'),
'--force' => $this->option('force')
]);
'--force' => $this->option('force'),
'--migration-file' => $migrationFile
];
if ($this->option('laravel')) {
$options['--laravel'] = true;
}
$this->call('wn:resource', $options);
$modelIndex++;
}
$this->call('migrate');
// $this->call('migrate'); // actually needed for pivot seeders !
$this->pivotTables = array_map(
'unserialize',
@ -72,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']){
$relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']);
foreach ($relations as $relation){
@ -124,6 +119,9 @@ class ResourcesCommand extends BaseCommand {
$name = $field['name'];
$schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':');
$rules = (isset($field['rules'])) ? trim($field['rules']) : '';
// Replace space by comma
$rules = str_replace(' ', ',', $rules);
$tags = $this->convertArray($field['tags'], ' ', ',');
$string = "{$name};{$schema};{$rules};{$tags}";

View File

@ -1,31 +1,66 @@
<?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class RouteCommand extends BaseCommand {
protected $signature = 'wn:route
{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.';
public function handle()
{
$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
$routesPath = './routes/web.php';
if (! $this->fs->exists($routesPath))
$routesPath = './app/Http/routes.php';
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| 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('routes')
->with([
'resource' => $resource,
'controller' => $this->getController()
])
->get();
$content .= PHP_EOL . $this->getTemplate($templateFile)
->with([
'resource' => $resource,
'controller' => $this->getController()
])
->get();
$this->save($content, $routesPath, "{$resource} routes", true);
}

View File

@ -2,7 +2,7 @@
class {{name}} extends Controller {
const MODEL = "{{model}}";
const MODEL = '{{model}}';
use RESTActions;

View File

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

View File

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

View File

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

View File

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

11
test.sh
View File

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