Browse Source

added prompt for the user, interface improved, multiply generation added

tags/2.0.0-beta
Mark 11 years ago
parent
commit
4204f896af
  1. 38
      extensions/yii/faker/FixtureController.php
  2. 14
      extensions/yii/faker/README.md

38
extensions/yii/faker/FixtureController.php

@ -59,7 +59,7 @@ use yii\helpers\Console;
* ~~~
* php yii faker/generate users
*
* #also a short version of this command (generate action is default)
* //also a short version of this command (generate action is default)
* php yii faker users
* ~~~
*
@ -84,13 +84,13 @@ use yii\helpers\Console;
* You can specify different options of this command:
*
* ~~~
* #generate fixtures in russian languge
* //generate fixtures in russian languge
* php yii faker/generate users 5 --language='ru_RU'
*
* #read templates from the other path
* //read templates from the other path
* php yii faker/generate all_fixtures --templatePath='@app/path/to/my/custom/templates'
*
* #generate fixtures into other folders, but be sure that this folders exists or you will get notice about that.
* //generate fixtures into other folders, but be sure that this folders exists or you will get notice about that.
* php yii faker/generate all_fixtures --fixturesPath='@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
* ~~~
*
@ -204,8 +204,12 @@ class FixtureController extends \yii\console\controllers\FixtureController
if ($this->needToGenerateAll($file)) {
$files = FileHelper::findFiles($templatePath, ['only' => ['.php']]);
} else {
$files = FileHelper::findFiles($templatePath, ['only' => [$file.'.php']]);
}
else {
foreach(explode(',', $file) as $fileName) {
$filesToSearch[] = $fileName . '.php';
}
$files = FileHelper::findFiles($templatePath, ['only' => $filesToSearch]);
}
if (empty($files)) {
@ -215,6 +219,10 @@ class FixtureController extends \yii\console\controllers\FixtureController
);
}
if (!$this->confirmGeneration($files)) {
return;
}
foreach ($files as $templateFile) {
$fixtureFileName = basename($templateFile);
$template = $this->getTemplate($templateFile);
@ -340,4 +348,22 @@ class FixtureController extends \yii\console\controllers\FixtureController
return $fixture;
}
/**
* Prompts user with message if he confirm generation with given fixture templates files.
* @param array $files
* @return boolean
*/
public function confirmGeneration($files)
{
$this->stdout("Fixtures will be generated under the path: \n", Console::FG_YELLOW);
$this->stdout(realpath(Yii::getAlias($this->fixturesPath, false)) ."\n\n", Console::FG_GREEN);
$this->stdout("Templates will be taken from path: \n", Console::FG_YELLOW);
$this->stdout(realpath(Yii::getAlias($this->templatePath, false)) . "\n\n", Console::FG_GREEN);
foreach ($files as $index => $fileName) {
$this->stdout(" " . $index +1 . ". " . basename($fileName) . "\n",Console::FG_GREEN);
}
return $this->confirm('Generate above fixtures?');
}
}

14
extensions/yii/faker/README.md

@ -40,7 +40,7 @@ To start using this command you need to be familiar (read guide) for the [Faker]
generate fixtures template files, according to the given format:
```php
#users.php file under template path (by default @tests/unit/templates/fixtures)
//users.php file under template path (by default @tests/unit/templates/fixtures)
return [
[
'table_column0' => 'faker_formatter',
@ -49,7 +49,7 @@ return [
'body' => function ($fixture, $faker, $index) {
//set needed fixture fields based on different conditions
$fixture['body'] = $faker->sentence(7,true); #generate sentence exact with 7 words.
$fixture['body'] = $faker->sentence(7,true); //generate sentence exact with 7 words.
return $fixture;
}
],
@ -87,10 +87,10 @@ return [
After you prepared needed templates for tables you can simply generate your fixtures via command
```php
#generate fixtures for the users table based on users fixture template
//generate fixtures for the users table based on users fixture template
php yii faker/generate users
#also a short version of this command ("generate" action is default)
//also a short version of this command ("generate" action is default)
php yii faker users
```
@ -113,13 +113,13 @@ php yii faker/generate all_fixtures 3
You can specify different options of this command:
```php
#generate fixtures in russian language
//generate fixtures in russian language
php yii faker/generate users 5 --language='ru_RU'
#read templates from the other path
//read templates from the other path
php yii faker/generate all_fixtures --templatePath='@app/path/to/my/custom/templates'
#generate fixtures into other folders, but be sure that this folders exists or you will get notice about that.
//generate fixtures into other folders, but be sure that this folders exists or you will get notice about that.
php yii faker/generate all_fixtures --fixturesPath='@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
```

Loading…
Cancel
Save