Update test-fixtures.md

This commit is contained in:
Aries Hc
2018-11-15 22:45:00 +08:00
committed by GitHub
parent b4fba57340
commit 18e3b3a756

View File

@ -163,9 +163,9 @@ $profile = $I->grabFixture('profiles', 'user1');
在后面,你可以通过如下的语法形式来访问 Fixture 提供的数据:
```php
// returns the UserProfile model corresponding to the data row aliased as 'user1'
// 返回对应于别名为“user1”的数据行的UserProfile模型
$profile = $I->grabFixture('profiles', 'user1');
// traverse data in the fixture
// 遍历 fixture 中的数据
foreach ($I->grabFixture('profiles') as $profile) ...
```
@ -206,18 +206,18 @@ data\
## 使用 `yii fixture` 来管理 fixtures
Yii supports fixtures via the `yii fixture` command line tool. This tool supports:
Yii 支持 fixtures 通过 `yii fixture` 命令行工具. 这个工具支持:
* Loading fixtures to different storage such as: RDBMS, NoSQL, etc;
* Unloading fixtures in different ways (usually it is clearing storage);
* Auto-generating fixtures and populating it with random data.
* fixtures 装载到不同的存储设备,例如:RDBMS, NoSQL;
* 以不同方式卸载 fixtures通常是清理存储;
* 自动生成 fixtures 并用随机数据填充。
### Fixtures 数据格式
让我们假设我们有要加载的 fixtures 数据:
```
#users.php file under fixtures data path, by default @tests\unit\fixtures\data
#users.php 文件在 fixtures 下的数据路径, 默认为 @tests\unit\fixtures\data
return [
[
@ -236,10 +236,10 @@ 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`
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-fixtures.md).
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.
如果我们使用 fixture 将数据加载到数据库中,那么这些行将应用于`users`表。 如果我们使用的是 nosql fixtures例如`mongodb` fixture然后这个数据将应用于`users` mongodb集合。 要了解有关实现各种加载策略的信息,请参阅官方[文档](https://github.com/yiisoft/yii2/blob/master/docs/guide/test-fixtures.md)。
上面的 fixture 示例由`yii2-faker`扩展自动生成,在这些[section](#auto-generating-fixtures) 中阅读更多相关内容。
Fixture 类名称不应为复数。.
### 加载 Fixtures
@ -248,7 +248,7 @@ Fixture 类应该以 `Fixture` 类作为后缀。默认的 Fixtures 能在 `test
运行如下命令去加载 Fixture
> Note: Prior to loading data unload sequence is executed. Usually that results in cleaning up all the existing data inserted by previous fixture executions.
> 注意:在加载数据之前,执行卸载序列。 通常,这会导致清除先前 fixture 执行所插入的所有现有数据。
```
yii fixture/load <fixture_name>
@ -258,30 +258,30 @@ yii fixture/load <fixture_name>
以下是这个命令的正确格式:
```
// load `User` fixture
// 加载 `User` fixture
yii fixture/load User
// same as above, because default action of "fixture" command is "load"
// 与上面相同因为“fixture”命令的默认动作是“加载”
yii fixture User
// load several fixtures
// 加载几个 fixtures
yii fixture User UserProfile
// load all fixtures
// 加载所有 fixtures
yii fixture/load "*"
// same as above
// 与上面相同
yii fixture "*"
// load all fixtures except ones
// 加载所有 fixtures 除了一些
yii fixture "*" -DoNotLoadThisOne
// load fixtures, but search them in different namespace. By default namespace is: tests\unit\fixtures.
// 加载 fixtures, 但在不同的命名空间中搜索它们。 默认命名空间是: tests\unit\fixtures.
yii fixture User --namespace='alias\my\custom\namespace'
// load global fixture `some\name\space\CustomFixture` before other fixtures will be loaded.
// By default this option is set to `InitDbFixture` to disable/enable integrity checks. You can specify several
// global fixtures separated by comma.
// 加载全局 fixture `some\name\space\CustomFixture` 在加载其他 fixtures 之前.
// 默认情况下,此选项设置为 “InitDbFixture” 以禁用/启用完整性检查。 您可以指定几个
// 全局 fixtures 用逗号分离.
yii fixture User --globalFixtures='some\name\space\Custom'
```
@ -290,16 +290,16 @@ yii fixture User --globalFixtures='some\name\space\Custom'
运行如下命名去卸载 Fixtures
```
// unload Users fixture, by default it will clear fixture storage (for example "users" table, or "users" collection if this is mongodb fixture).
// 卸载用户 fixture默认情况下它将清除夹具存储例如“用户”表或“用户”集合如果这是 mongodb fixture)。
yii fixture/unload User
// Unload several fixtures
// 卸载几个 fixtures
yii fixture/unload User,UserProfile
// unload all fixtures
// 卸载所有 fixtures
yii fixture/unload "*"
// unload all fixtures except ones
// 卸载所有 fixtures 除了一些
yii fixture/unload "*" -DoNotUnloadThisOne
```