$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"];'); $I->wantTo('generate a model with dates fields'); $I->runShellCommand('php artisan wn:model TestingModel --dates=started_at --path=tests/tmp');
$I->runShellCommand('mkdir ' . $outputPath); $I->runShellCommand('php extract_markdown_codes.php ' . $inputPath . ' list ' . $outputPath); // assertions $I->amInPath($outputPath); // list1 (function () use($I) { $I->openFile('list001.txt'); $contents = <<<EOT // list1 require_once __DIR__ . '/vendor/autoload.php'; \$foo = new Foo(); \$foo->execute(); EOT; $I->seeFileContentsEqual($contents); })(); // list2 (function () use($I) { $I->openFile('list002.txt'); $contents = <<<EOT // list2 \$i = 2; EOT; $I->seeFileContentsEqual($contents); })(); // list3 (function () use($I) { $I->openFile('list003.txt'); $contents = <<<EOT
<?php $I = new AcceptanceTester($scenario); $I->wantTo('Generate the full structure of a new module for Backbone / RequireJS'); // Make sure that we're dealing with a clean directory $I->cleanDir('tests/tmp'); $I->runShellCommand('php ../../../artisan modules:generate taco --path=tests/tmp/modules'); $I->seeInShellOutput('Successfully created 4 files'); $I->openFile('tests/tmp/modules/tacos/models/taco.js'); $I->seeFileContentsEqual(file_get_Contents('tests/acceptance/stubs/model.stub')); $I->openFile('tests/tmp/modules/tacos/collections/tacos.js'); $I->seeFileContentsEqual(file_get_Contents('tests/acceptance/stubs/collection.stub')); $I->openFile('tests/tmp/modules/tacos/views/taco_view.js'); $I->seeFileContentsEqual(file_get_Contents('tests/acceptance/stubs/view.stub')); $I->openFile('tests/tmp/modules/tacos/index.js'); $I->seeFileContentsEqual(file_get_Contents('tests/acceptance/stubs/index.stub')); $I->cleanDir('tests/tmp');
$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(); }); } public function down() { Schema::drop(\'project_tag\'); } } '); $I->deleteFile('./database/migrations/pivot_table.php');
<?php $saveDir = './tests/acceptance/tmp'; $stubDir = './tests/acceptance/stubs'; $queryToGenerate = 'FooQuery'; $I = new AcceptanceTester($scenario); $I->wantTo('generate a query and handler class'); $I->runShellCommand("php ../../../artisan querier:generate {$queryToGenerate} --properties='bar, baz' --base='{$saveDir}'"); $I->seeInShellOutput('All done!'); // My Command stub should match the generated class. $I->openFile("{$saveDir}/{$queryToGenerate}.php"); $I->seeFileContentsEqual(file_get_contents("{$stubDir}/{$queryToGenerate}.stub")); // And my QueryHandler stub should match its generated counterpart, as well. $I->openFile("{$saveDir}/{$queryToGenerate}Handler.php"); $I->seeFileContentsEqual(file_get_contents("{$stubDir}/{$queryToGenerate}Handler.stub")); $I->cleanDir($saveDir);
$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\'); } } '); $I->deleteFile('./database/migrations/create_tasks.php'); $I->wantTo('generate a migration with schema'); $I->runShellCommand('php artisan wn:migration tasks --file=create_tasks --schema="amount:decimal.5,2:after.\'size\':default.8 title:string:nullable"'); $I->seeInShellOutput('tasks migration generated');
<?php $I = new AcceptanceTester($scenario); $I->wantTo('generate both a command and a hndler class'); $I->runShellCommand('php artisan commander:generate Acme/Bar/FooCommand --properties="bar, baz" --base="tests/tmp"'); $I->seeInShellOutput('All done!'); $I->openFile('tests/tmp/Acme/Bar/FooCommand.php'); $I->seeFileContentsEqual(file_get_contents('tests/acceptance/stub/FooCommand.stub')); //$I->seeFileFound('tests/tmp/FooCommandHandler.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";