mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-17 07:51:12 +08:00
docs improved
This commit is contained in:
@ -39,6 +39,7 @@ return [
|
|||||||
If we are using fixture that loads data into database then these rows will be applied to `users` table. If we are using nosql fixtures, for example `mongodb`
|
If we are using fixture that loads data into database then these rows will be applied to `users` table. If we are using nosql fixtures, for example `mongodb`
|
||||||
fixture, then this data will be applied to `users` mongodb collection. In order to learn about implementing various loading strategies and more, refer to official [documentation](https://github.com/yiisoft/yii2/blob/master/docs/guide/test-fixture.md).
|
fixture, then this data will be applied to `users` mongodb collection. In order to learn about implementing various loading strategies and more, refer to official [documentation](https://github.com/yiisoft/yii2/blob/master/docs/guide/test-fixture.md).
|
||||||
Above fixture example was auto-generated by `yii2-faker` extension, read more about it in these [section](#auto-generating-fixtures).
|
Above fixture example was auto-generated by `yii2-faker` extension, read more about it in these [section](#auto-generating-fixtures).
|
||||||
|
Fixture classes name should not be plural.
|
||||||
|
|
||||||
Loading fixtures
|
Loading fixtures
|
||||||
----------------
|
----------------
|
||||||
@ -57,13 +58,13 @@ Below are correct formats of this command:
|
|||||||
|
|
||||||
```
|
```
|
||||||
// apply `users` fixture
|
// apply `users` fixture
|
||||||
yii fixture/apply Users
|
yii fixture/apply User
|
||||||
|
|
||||||
// same as above, because default action of "fixture" command is "apply"
|
// same as above, because default action of "fixture" command is "apply"
|
||||||
yii fixture Users
|
yii fixture User
|
||||||
|
|
||||||
// apply several fixtures. Note that there should not be any whitespace between ",", it should be one string.
|
// apply several fixtures. Note that there should not be any whitespace between ",", it should be one string.
|
||||||
yii fixture Users,UsersProfiles
|
yii fixture User,UserProfile
|
||||||
|
|
||||||
// apply all fixtures
|
// apply all fixtures
|
||||||
yii fixture/apply all
|
yii fixture/apply all
|
||||||
@ -71,17 +72,11 @@ yii fixture/apply all
|
|||||||
// same as above
|
// same as above
|
||||||
yii fixture all
|
yii fixture all
|
||||||
|
|
||||||
// apply Users fixture, but fixture will be taken from different path.
|
|
||||||
yii fixture Users --fixturePath='@app/my/custom/path/to/fixtures'
|
|
||||||
|
|
||||||
// apply fixtures, but for other database connection.
|
// apply fixtures, but for other database connection.
|
||||||
yii fixtures Users --db='customDbConnectionId'
|
yii fixtures User --db='customDbConnectionId'
|
||||||
|
|
||||||
// apply fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
|
// apply fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
|
||||||
yii fixtures Users --namespace='my/custom/namespace'
|
yii fixtures User --namespace='alias\my\custom\namespace'
|
||||||
|
|
||||||
// apply fixtures without namespace under fixturesPath
|
|
||||||
yii fixtures all --namespace=''
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Unloading fixtures
|
Unloading fixtures
|
||||||
@ -91,16 +86,16 @@ To unload fixture, run the following command:
|
|||||||
|
|
||||||
```
|
```
|
||||||
// unload Users fixture, by default it will clear fixture storage (for example "users" table, or "users" collection if this is mongodb fixture).
|
// unload Users fixture, by default it will clear fixture storage (for example "users" table, or "users" collection if this is mongodb fixture).
|
||||||
yii fixture/clear Users
|
yii fixture/clear User
|
||||||
|
|
||||||
// Unload several fixtures. Note that there should not be any whitespace between ",", it should be one string.
|
// Unload several fixtures. Note that there should not be any whitespace between ",", it should be one string.
|
||||||
yii fixture/clear Users,UsersProfiles
|
yii fixture/clear User,UserProfile
|
||||||
|
|
||||||
// unload all fixtures
|
// unload all fixtures
|
||||||
yii fixture/clear all
|
yii fixture/clear all
|
||||||
```
|
```
|
||||||
|
|
||||||
Same command options like: `fixturesPath`, `db`, `namespace` also can be applied to this command.
|
Same command options like: `db`, `namespace` also can be applied to this command.
|
||||||
|
|
||||||
Configure Command Globally
|
Configure Command Globally
|
||||||
--------------------------
|
--------------------------
|
||||||
@ -112,8 +107,8 @@ different migration path as follows:
|
|||||||
'controllerMap' => [
|
'controllerMap' => [
|
||||||
'fixture' => [
|
'fixture' => [
|
||||||
'class' => 'yii\console\FixtureController',
|
'class' => 'yii\console\FixtureController',
|
||||||
'fixturePath' => '@app/my/custom/path/to/fixtures',
|
|
||||||
'db' => 'customDbConnectionId',
|
'db' => 'customDbConnectionId',
|
||||||
|
'namespace' => 'myalias\some\custom\namespace',
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
Reference in New Issue
Block a user