Compare commits

..

No commits in common. "master" and "1.2.0" have entirely different histories.

55 changed files with 1913 additions and 1224 deletions

View File

@ -1,14 +0,0 @@
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

2
.gitignore vendored
View File

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

View File

@ -4,7 +4,6 @@ php:
- 5.5 - 5.5
- 5.6 - 5.6
- 7.0 - 7.0
- 7.1
- hhvm - hhvm
matrix: matrix:

View File

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

View File

@ -1,11 +1,9 @@
# Lumen generators # Lumen generators
[![Build Status](https://travis-ci.org/webNeat/lumen-generators.svg?branch=master)](https://travis-ci.org/webNeat/lumen-generators) [![Build Status](https://travis-ci.org/webNeat/lumen-generators.svg?branch=master)](https://travis-ci.org/webNeat/lumen-generators)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/webNeat/lumen-generators/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/webNeat/lumen-generators/?branch=master) [![License](https://poser.pugx.org/laravel/framework/license.svg)](http://opensource.org/licenses/MIT)
[![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 6](http://laravel.com/). A collection of generators for [Lumen](http://lumen.laravel.com) and [Laravel 5](http://laravel.com/).
## Contents ## Contents
@ -81,7 +79,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" --add=timestamps --belongs-to=project php artisan wn:resource task "name;string;required;fillable project_id;integer:unsigned;numeric;fillable,key due;date;;date" --belongs-to=project
``` ```
will generate these files: will generate these files:
@ -259,7 +257,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=...] [--timestamps=false] [--path=...] [--soft-deletes=true] [--force=true] wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--path=...] [--force=true]
``` ```
- **name**: the name of the model. - **name**: the name of the model.
@ -359,10 +357,6 @@ 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: - **--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:
``` ```
@ -374,7 +368,7 @@ TestingModel model already exists; use --force option to override it !
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=...] [--add=...] [--keys=...] [--force=true] [--file=...] wn:migration table [--schema=...] [--keys=...] [--force=true] [--file=...]
``` ```
- **table**: the name of the table to create. - **table**: the name of the table to create.
@ -404,7 +398,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();
}); });
} }
@ -415,8 +409,6 @@ 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.
``` ```
@ -441,17 +433,15 @@ $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 [--add=...] [--force=true] [--file=...] wn:pivot-table model1 model2 [--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 --add=timestamps php artisan wn:pivot-table Tag Project
``` ```
gives: gives:
@ -511,8 +501,6 @@ The second command is `wn:controller` which actually generates the controller. T
- **--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: `php artisan wn:controller Task --no-routes` gives:
@ -541,9 +529,6 @@ The `wn:route` command is used to generate RESTfull routes for a controller. It
- **--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:route project-type` adds the following routes: `php artisan wn:route project-type` adds the following routes:
```php ```php
@ -554,20 +539,9 @@ $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 [--add=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--migration-file=...] [--path=...] [--force=true]` 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=...] [--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.
@ -587,8 +561,6 @@ 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.
@ -597,9 +569,6 @@ The `wn:resource` command makes it very easy to generate a RESTful resource. It
- **--force**: tells the generator to override the existing file. - **--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
@ -614,9 +583,6 @@ 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. - **--path**: Defines where to store the model files as well as their namespace.
- **--laravel**: create Laravel style routes
```yaml ```yaml
--- ---
Store: Store:
@ -648,7 +614,6 @@ 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
@ -661,31 +626,9 @@ To test the generators, I included a fresh lumen installation under the folder `
- **Seeder and Test generators** - **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: [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) - Requested Feature: [Custom Templates](https://github.com/webNeat/lumen-generators/issues/13)
- **Version 1.2.0** - **Version 1.2.0**

View File

@ -1,5 +1,5 @@
{ {
"name": "zorgcc/lumen-generators", "name": "wn/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,10 +10,10 @@
} }
], ],
"require": { "require": {
"php": "^7.2", "php": ">=5.5.0",
"illuminate/console": "^5.1|^6", "illuminate/console": "^5.1",
"illuminate/filesystem": "^5.1|^6", "illuminate/filesystem": "^5.1",
"fzaninotto/faker": "^1.5" "fzaninotto/faker": "^1.5"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

1951
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ APP_KEY=SomeRandomKey!!!
# APP_LOCALE=en # APP_LOCALE=en
# APP_FALLBACK_LOCALE=en # APP_FALLBACK_LOCALE=en
DB_CONNECTION=sqlite # DB_CONNECTION=mysql
# DB_HOST=localhost # DB_HOST=localhost
# DB_PORT=3306 # DB_PORT=3306
# DB_DATABASE=homestead # DB_DATABASE=homestead

View File

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

View File

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

View File

@ -1,51 +0,0 @@
# 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,7 +5,6 @@ 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: false colors: false

View File

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

22
lumen-test/models.yml Normal file
View File

@ -0,0 +1,22 @@
---
Post:
belongsToMany: tags
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

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

View File

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

View File

@ -1,4 +1,4 @@
<?php //[STAMP] 1467e0d5027bbc2413077351642a21f3 <?php //[STAMP] afa4f0350422fae145b4236dce66191a
namespace _generated; namespace _generated;
// This class was automatically generated by build task // This class was automatically generated by build task
@ -19,29 +19,14 @@ trait UnitTesterActions
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
* Checks that two variables are equal. If you're comparing floating-point values, * Checks that two variables are equal.
* 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
* @see \Codeception\Module\Asserts::assertEquals() * @see \Codeception\Module\Asserts::assertEquals()
*/ */
public function assertEquals($expected, $actual, $message = null, $delta = null) { public function assertEquals($expected, $actual, $message = 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()));
} }
@ -49,29 +34,14 @@ 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. If you're comparing floating-point values, * Checks that two variables are not equal
* 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, $delta = null) { public function assertNotEquals($expected, $actual, $message = 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()));
} }
@ -84,6 +54,7 @@ trait UnitTesterActions
* @param $expected * @param $expected
* @param $actual * @param $actual
* @param string $message * @param string $message
* @return mixed|void
* @see \Codeception\Module\Asserts::assertSame() * @see \Codeception\Module\Asserts::assertSame()
*/ */
public function assertSame($expected, $actual, $message = null) { public function assertSame($expected, $actual, $message = null) {
@ -226,36 +197,6 @@ 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.
* *
@ -432,22 +373,6 @@ 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. * [!] Method is generated. Documentation taken from corresponding module.
* *

View File

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

View File

@ -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 --add=timestamps --file=create_tasks'); $I->runShellCommand('php artisan wn:migration tasks --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,39 +32,8 @@ 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 --add=timestamps --file=create_tasks --schema="amount:decimal.5,2:after.\'size\':default.8 title:string:nullable"'); $I->runShellCommand('php artisan wn:migration tasks --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');

View File

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

View File

@ -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 --add=timestamps --file=pivot_table'); $I->runShellCommand('php artisan wn:pivot-table Tag Project --file=pivot_table');
$I->seeInShellOutput('project_tag migration generated'); $I->seeInShellOutput('project_tag migration generated');
$I->seeFileFound('./database/migrations/pivot_table.php'); $I->seeFileFound('./database/migrations/pivot_table.php');
$I->openFile('./database/migrations/pivot_table.php'); $I->openFile('./database/migrations/pivot_table.php');

View File

@ -2,7 +2,7 @@
$I = new AcceptanceTester($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('generate a RESTful resource'); $I->wantTo('generate a RESTful resource');
$I->runShellCommand('php artisan wn:resource task_category "name;string:unique;requied;fillable;word descr;text:nullable;;fillable;paragraph due;timestamp;;fillable,date;date" --has-many="tags,tasks" --belongs-to="project,creator:User" --add=timestamps --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" --migration-file=create_task_categories');
// Checking the model // Checking the model
$I->seeInShellOutput('TaskCategory model generated'); $I->seeInShellOutput('TaskCategory model generated');

View File

@ -1,136 +0,0 @@
<?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

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

View File

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

View File

@ -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 = (isset($matches[2][0]) && $matches[2][0] === '['); $isArray = (@$matches[2][0] === '[');
return [$attr, $type, $isArray]; return [$attr, $type, $isArray];
} }

View File

@ -1,15 +1,12 @@
<?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} {--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';
@ -34,17 +31,12 @@ class ControllerCommand extends BaseCommand {
->get(); ->get();
$this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}"); $this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
if(! $this->option('no-routes')){ if(! $this->option('no-routes')){
$options = [ $this->call('wn:route', [
'resource' => snake_case($name, '-'), 'resource' => snake_case($name, '-'),
'--controller' => $controller, '--controller' => $controller
]; ]);
if ($this->option('laravel')) {
$options['--laravel'] = true;
}
$this->call('wn:route', $options);
} }
} }

View File

@ -3,25 +3,24 @@
class MigrationCommand extends BaseCommand { 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.} {--add= : specifies additional columns like 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} {--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
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() public function handle()
{ {
$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([
@ -35,26 +34,12 @@ class MigrationCommand extends BaseCommand {
$file = $this->option('file'); $file = $this->option('file');
if(! $file){ if(! $file){
$file = date('Y_m_d_His_') . $snakeName . '_table'; $file = date('Y_m_d_His_') . snake_case($name) . '_table';
$this->deleteOldMigration($snakeName);
}else{
$this->deleteOldMigration($file);
} }
$this->save($content, "./database/migrations/{$file}.php", "{$table} migration"); $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() protected function getSchema()
{ {
$schema = $this->option('schema'); $schema = $this->option('schema');
@ -79,7 +64,7 @@ class MigrationCommand extends BaseCommand {
{ {
$additionals = $this->option('add'); $additionals = $this->option('add');
if (empty($additionals)) { if (empty($additionals)) {
return ''; $additionals = 'timestamps';
} }
$additionals = explode(',', $additionals); $additionals = explode(',', $additionals);
@ -142,20 +127,20 @@ class MigrationCommand extends BaseCommand {
if($key['on_delete']){ if($key['on_delete']){
$constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint')
->with([ ->with([
'event' => 'Delete', 'event' => 'Delete',
'action' => $key['on_delete'] 'action' => $key['on_delete']
]) ])
->get(); ->get();
} }
if($key['on_update']){ if($key['on_update']){
$constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint')
->with([ ->with([
'event' => 'Update', 'event' => 'Update',
'action' => $key['on_update'] 'action' => $key['on_update']
]) ])
->get(); ->get();
} }
return $constraint . ';'; return $constraint . ';';

View File

@ -12,9 +12,7 @@ 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.}
{--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} {--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} {--force= : override the existing files}
'; ';
@ -33,9 +31,7 @@ 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();
@ -118,18 +114,4 @@ class ModelCommand extends BaseCommand {
return implode(PHP_EOL, $rules); return implode(PHP_EOL, $rules);
} }
protected function getAdditional()
{
return $this->option('timestamps') == 'false'
? " public \$timestamps = false;" . PHP_EOL . PHP_EOL
: '';
}
protected function getUses()
{
return $this->option('soft-deletes') == 'true'
? ' use \Illuminate\Database\Eloquent\SoftDeletes;' . PHP_EOL . PHP_EOL
: '';
}
} }

View File

@ -6,7 +6,6 @@ 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} {--force= : override the existing files}
'; ';
@ -25,8 +24,7 @@ class PivotTableCommand extends BaseCommand {
'--keys' => $this->keys(), '--keys' => $this->keys(),
'--file' => $this->option('file'), '--file' => $this->option('file'),
'--parsed' => false, '--parsed' => false,
'--force' => $this->option('force'), '--force' => $this->option('force')
'--add' => $this->option('add')
]); ]);
} }

View File

@ -1,8 +1,6 @@
<?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
@ -13,11 +11,9 @@ 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.} {--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} {--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';
@ -44,8 +40,6 @@ class ResourceCommand extends BaseCommand {
'--rules' => $this->rules(), '--rules' => $this->rules(),
'--path' => $this->option('path'), '--path' => $this->option('path'),
'--force' => $this->option('force'), '--force' => $this->option('force'),
'--timestamps' => $this->hasTimestamps() ? 'true' : 'false',
'--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false',
'--parsed' => true '--parsed' => true
]); ]);
@ -56,7 +50,6 @@ class ResourceCommand extends BaseCommand {
'--keys' => $this->migrationKeys(), '--keys' => $this->migrationKeys(),
'--file' => $this->option('migration-file'), '--file' => $this->option('migration-file'),
'--force' => $this->option('force'), '--force' => $this->option('force'),
'--add' => $this->option('add'),
'--parsed' => true '--parsed' => true
]); ]);
@ -64,16 +57,13 @@ class ResourceCommand extends BaseCommand {
if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){
$this->call('wn:controller:rest-actions'); $this->call('wn:controller:rest-actions');
} }
// generating the controller and routes // generating the controller and routes
$controllerOptions = [ $this->call('wn:controller', [
'model' => $modelName, 'model' => $modelName,
'--force' => $this->option('force'), '--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 // generating model factory
$this->call('wn:factory', [ $this->call('wn:factory', [
@ -190,18 +180,4 @@ class ResourceCommand extends BaseCommand {
})); }));
} }
protected function hasTimestamps()
{
$additionals = explode(',', $this->option('add'));
return in_array('nullableTimestamps', $additionals)
|| in_array('timestamps', $additionals)
|| in_array('timestampsTz', $additionals);
}
protected function hasSoftDeletes()
{
$additionals = explode(',', $this->option('add'));
return in_array('softDeletes', $additionals);
}
} }

View File

@ -1,6 +1,5 @@
<?php namespace Wn\Generators\Commands; <?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
@ -10,8 +9,6 @@ class ResourcesCommand extends BaseCommand {
{file : Path to the file containing resources declarations} {file : Path to the file containing resources declarations}
{--path=app : where to store the model files.} {--path=app : where to store the model files.}
{--force= : override the existing 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';
@ -23,34 +20,22 @@ 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'), '--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'); // actually needed for pivot seeders ! // $this->call('migrate');
$this->pivotTables = array_map( $this->pivotTables = array_map(
'unserialize', 'unserialize',
@ -71,14 +56,14 @@ class ResourcesCommand extends BaseCommand {
// ]); // ]);
} }
$this->call('migrate'); // $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', 'add', 'belongsTo', 'belongsToMany'] as $relation){ foreach(['hasMany', 'hasOne', '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 {
@ -86,6 +71,25 @@ 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){
@ -119,9 +123,6 @@ class ResourcesCommand extends BaseCommand {
$name = $field['name']; $name = $field['name'];
$schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':'); $schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':');
$rules = (isset($field['rules'])) ? trim($field['rules']) : ''; $rules = (isset($field['rules'])) ? trim($field['rules']) : '';
// Replace space by comma
$rules = str_replace(' ', ',', $rules);
$tags = $this->convertArray($field['tags'], ' ', ','); $tags = $this->convertArray($field['tags'], ' ', ',');
$string = "{$name};{$schema};{$rules};{$tags}"; $string = "{$name};{$schema};{$rules};{$tags}";

View File

@ -1,67 +1,28 @@
<?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
use Illuminate\Http\Request; $content = $this->fs->get('./app/Http/routes.php');
/* $content .= PHP_EOL . $this->getTemplate('routes')
|-------------------------------------------------------------------------- ->with([
| API Routes 'resource' => $resource,
|-------------------------------------------------------------------------- 'controller' => $this->getController()
| ])
| Here is where you can register API routes for your application. These ->get();
| 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) { $this->save($content, './app/Http/routes.php', "{$resource} routes", true);
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([
'resource' => $resource,
'controller' => $this->getController()
])
->get();
$this->save($content, $routesPath, "{$resource} routes", true);
} }
protected function getController() protected function getController()

View File

@ -16,9 +16,9 @@ class CommandsServiceProvider extends ServiceProvider
$this->registerResourcesCommand(); $this->registerResourcesCommand();
$this->registerPivotTableCommand(); $this->registerPivotTableCommand();
$this->registerFactoryCommand(); $this->registerFactoryCommand();
// registerSeederCommand // $this->registerSeederCommand();
// registerPivotSeederCommand // $this->registerPivotSeederCommand();
// registerTestCommand // $this->registerTestCommand();
} }
protected function registerModelCommand(){ protected function registerModelCommand(){

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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