<?php $I = new AcceptanceTester($scenario); $I->wantTo('generate a model without fillable fields or dates'); $I->runShellCommand('php artisan wn:model TestingModel --path=tests/tmp'); $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 ]; // Relationships } '); $I->wantTo('generate a model with fillable fields'); $I->runShellCommand('php artisan wn:model TestingModel --fillable=name,title --path=tests/tmp'); $I->seeFileFound('./tests/tmp/TestingModel.php'); $I->openFile('./tests/tmp/TestingModel.php'); $I->seeInThisFile('protected $fillable = ["name", "title"];');
<?php $I = new AcceptanceTester($scenario); $I->wantTo('generate a RESTful resource'); $I->runShellCommand('php artisan wn:resource task_category "name;string:unique;requied;fillable descr;text:nullable;;fillable project_id;integer;required;key,fillable due;timestamp;;fillable,date" --has-many="tags,tasks" --belongs-to="project,creator:User" --migration-file=create_task_categories'); // Checking the model $I->seeInShellOutput('TaskCategory model generated'); $I->seeFileFound('./app/TaskCategory.php'); $I->openFile('./app/TaskCategory.php'); $I->seeInThisFile('namespace App;'); $I->seeInThisFile('class TaskCategory extends Model'); $I->seeInThisFile('protected $fillable = ["name", "descr", "project_id", "due"];'); $I->seeInThisFile('protected $dates = ["due"];'); $I->seeInThisFile('public static $rules = [ "name" => "requied", "project_id" => "required", ];'); $I->seeInThisFile(' public function tags() { return $this->hasMany("App\\Tag"); } public function tasks() { return $this->hasMany("App\\Task"); } public function project() { return $this->belongsTo("App\\Project");
<?php $I = new AcceptanceTester($scenario); $I->wantTo('generate a pivot table'); $I->runShellCommand('php artisan wn:pivot-table Tag Project --file=pivot_table'); $I->seeInShellOutput('project_tag migration generated'); $I->seeFileFound('./database/migrations/pivot_table.php'); $I->openFile('./database/migrations/pivot_table.php'); $I->seeFileContentsEqual('<?php use Illuminate\\Database\\Schema\\Blueprint; use Illuminate\\Database\\Migrations\\Migration; class CreateProjectTagTable extends Migration { public function up() { Schema::create(\'project_tag\', function(Blueprint $table) { $table->increments(\'id\'); $table->integer(\'project_id\')->unsigned()->index(); $table->integer(\'tag_id\')->unsigned()->index(); $table->foreign(\'project_id\') ->references(\'id\') ->on(\'projects\'); $table->foreign(\'tag_id\') ->references(\'id\') ->on(\'tags\'); $table->timestamps(); }); }
<?php $I = new AcceptanceTester($scenario); $I->wantTo('generate a migration without schema'); $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 CreateTasksMigration extends Migration { public function up() { Schema::create(\'tasks\', function(Blueprint $table) { $table->increments(\'id\'); // Schema declaration // Constraints declaration $table->timestamps(); }); } public function down() { Schema::drop(\'tasks\'); } }
<?php $I = new AcceptanceTester($scenario); $I->wantTo('generate the REST actions trait'); $I->runShellCommand('php artisan wn:controller:rest-actions'); $I->seeInShellOutput('REST actions trait generated'); $I->seeFileFound('./app/Http/Controllers/RESTActions.php'); $I->openFile('./app/Http/Controllers/RESTActions.php'); $I->seeInThisFile('trait RESTActions {'); $I->deleteFile('./app/Http/Controllers/RESTActions.php');
<?php $I = new AcceptanceTester($scenario); $I->wantTo('generate a RESTful controller with short model name'); $I->runShellCommand('php artisan wn:controller Test --no-routes'); $I->seeInShellOutput('TestsController generated'); $I->seeFileFound('./app/Http/Controllers/TestsController.php'); $I->openFile('./app/Http/Controllers/TestsController.php'); $I->seeFileContentsEqual('<?php namespace App\\Http\\Controllers; class TestsController extends Controller { const MODEL = "App\\Test"; use RESTActions; } '); $I->deleteFile('./app/Http/Controllers/TestsController.php'); $I->wantTo('generate a RESTful controller with full model name and routes'); $I->runShellCommand('php artisan wn:controller "App\\Models\\Category"'); $I->seeInShellOutput('CategoriesController generated'); $I->seeFileFound('./app/Http/Controllers/CategoriesController.php'); $I->openFile('./app/Http/Controllers/CategoriesController.php'); $I->seeFileContentsEqual('<?php namespace App\\Http\\Controllers; class CategoriesController extends Controller { const MODEL = "App\\Models\\Category";