Commit 19af2645 by Alexander Makarov

Enh: `yii fixture` command now offers help if no arguments are provided instead of crashing

parent 7325fdd7
...@@ -14,13 +14,13 @@ use yii\helpers\FileHelper; ...@@ -14,13 +14,13 @@ use yii\helpers\FileHelper;
use yii\helpers\VarDumper; use yii\helpers\VarDumper;
/** /**
* This command manage fixtures creations based on given template. * This command creates fixtures based on a given template.
* *
* Fixtures are one of the important paths in unit testing. To speed up developers * Fixtures are one of the important paths in unit testing. To speed up developers
* work these fixtures can be generated automatically, based on prepared template. * work these fixtures can be generated automatically, based on prepared template.
* This command is a simple wrapper for the fixtures library [Faker](https://github.com/fzaninotto/Faker). * This command is a simple wrapper for the [Faker](https://github.com/fzaninotto/Faker) library.
* *
* You should configure this command as follows (you can use any alias, not only "fixture"): * You should configure your application as follows (you can use any alias, not only "fixture"):
* *
* ~~~ * ~~~
* 'controllerMap' => [ * 'controllerMap' => [
...@@ -30,7 +30,7 @@ use yii\helpers\VarDumper; ...@@ -30,7 +30,7 @@ use yii\helpers\VarDumper;
* ], * ],
* ~~~ * ~~~
* *
* To start using this command you need to be familiar (read guide) for the Faker library and * To start using the command you need to be familiar (read guide) with the Faker library and
* generate fixtures template files, according to the given format: * generate fixtures template files, according to the given format:
* *
* ```php * ```php
...@@ -45,7 +45,7 @@ use yii\helpers\VarDumper; ...@@ -45,7 +45,7 @@ use yii\helpers\VarDumper;
* ]; * ];
* ``` * ```
* *
* If you use callback as a attribute value, then it will be called as shown with three parameters: * If you use callback as an attribute value it will be called with the following three parameters:
* *
* - `$faker`: the Faker generator instance * - `$faker`: the Faker generator instance
* - `$index`: the current fixture index. For example if user need to generate 3 fixtures for user table, it will be 0..2. * - `$index`: the current fixture index. For example if user need to generate 3 fixtures for user table, it will be 0..2.
......
...@@ -71,6 +71,7 @@ Yii Framework 2 Change Log ...@@ -71,6 +71,7 @@ Yii Framework 2 Change Log
- Enh: `Console::confirm()` now uses `Console::stdout()` instead of `echo` to be consistent with all other functions (cebe) - Enh: `Console::confirm()` now uses `Console::stdout()` instead of `echo` to be consistent with all other functions (cebe)
- Enh: `yii\rbac\DbManager` migration now uses database component specified in component settings instead of always using default `db` (samdark) - Enh: `yii\rbac\DbManager` migration now uses database component specified in component settings instead of always using default `db` (samdark)
- Enh: Added `yii\base\Controller::renderContent()` (qiangxue) - Enh: Added `yii\base\Controller::renderContent()` (qiangxue)
- Enh: `yii fixture` command now offers help if no arguments are provided instead of crashing (samdark)
- Chg #3630: `yii\db\Command::queryInternal()` is now protected (samdark) - Chg #3630: `yii\db\Command::queryInternal()` is now protected (samdark)
- Chg #4277: `yii\grid\GridView` is no longer throwing an exception when results are empty and `columns` aren't defined (samdark) - Chg #4277: `yii\grid\GridView` is no longer throwing an exception when results are empty and `columns` aren't defined (samdark)
- Chg #5508: Dropped the support for the `--append` option for the `fixture` command (qiangxue) - Chg #5508: Dropped the support for the `--append` option for the `fixture` command (qiangxue)
......
...@@ -91,6 +91,15 @@ class FixtureController extends Controller ...@@ -91,6 +91,15 @@ class FixtureController extends Controller
public function actionLoad() public function actionLoad()
{ {
$fixturesInput = func_get_args(); $fixturesInput = func_get_args();
if ($fixturesInput === []) {
$this->stdout($this->getHelpSummary() . "\n");
$helpCommand = Console::ansiFormat("yii help fixture", [Console::FG_CYAN]);
$this->stdout("Use $helpCommand to get usage info.\n");
return self::EXIT_CODE_NORMAL;
}
$filtered = $this->filterFixtures($fixturesInput); $filtered = $this->filterFixtures($fixturesInput);
$except = $filtered['except']; $except = $filtered['except'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment