lumen-generators/lumen-test/tests/acceptance/FactoryCommandCept.php

69 lines
2.2 KiB
PHP
Raw Normal View History

2016-12-29 18:35:34 +03:00
<?php
2016-02-19 23:17:03 +03:00
$I = new AcceptanceTester($scenario);
2015-10-21 01:34:10 +03:00
2016-02-19 23:17:03 +03:00
$I->wantTo('generate model factories without fields');
$I->runShellCommand('php artisan wn:factory "App\Task"');
$I->seeInShellOutput('App\Task factory generated');
$I->openFile('./database/factories/ModelFactory.php');
$I->seeInThisFile('
$factory->define(App\Task::class, function ($faker) {
return [
2016-12-29 18:35:34 +03:00
// Fields here
2016-02-19 23:17:03 +03:00
];
});');
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
2015-10-21 01:34:10 +03:00
2016-02-19 23:17:03 +03:00
/*
|--------------------------------------------------------------------------
| 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.
|
*/
2015-10-21 01:34:10 +03:00
2016-02-19 23:17:03 +03:00
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
");
2015-10-21 01:34:10 +03:00
2016-02-19 23:17:03 +03:00
$I->wantTo('generate model factories with fields');
$I->runShellCommand('php artisan wn:factory "App\Task" --fields="title:sentence(3),description:paragraph(3),due:date,hidden:boolean"');
$I->seeInShellOutput('App\Task factory generated');
$I->openFile('./database/factories/ModelFactory.php');
$I->seeInThisFile(
" 'title' => \$faker->sentence(3)," . PHP_EOL .
" 'description' => \$faker->paragraph(3)," . PHP_EOL .
" 'due' => \$faker->date," . PHP_EOL .
" 'hidden' => \$faker->boolean,"
);
2016-02-19 23:17:03 +03:00
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
2015-10-21 01:34:10 +03:00
2016-02-19 23:17:03 +03:00
/*
|--------------------------------------------------------------------------
| 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.
|
*/
2015-10-21 01:34:10 +03:00
2016-02-19 23:17:03 +03:00
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
");