Yii2验收测试。在每个测试之后回滚在验收测试中所做的所有更改

时间:2018-12-12 16:00:22

标签: yii2 codeception acceptance-testing

我需要在每次验收测试之后恢复通过验收测试对数据库所做的所有更改。

如Yii2文档中所述,您应该在HttpClient中为transaction: false模块设置Yii2。 并且您应该在acceptance.suite.yml中的cleanup: true and transaction: true模块中使用Db

实际不恢复数据库中验收测试所做的更改。

预期:将还原数据库中验收测试所做的更改。

codeception.yml

codeception.yml

acceptance.suite.yml

namespace: common\tests
actor_suffix: Tester
paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
modules:
    config:
        Yii2:
            configFile: 'config/test-local.php'
        Db:
            dsn: '%TEST_DB_TYPE%:host=%TEST_DB_HOST%;port=%TEST_DB_PORT%;dbname=%TEST_DB_NAME%'
            user: '%TEST_DB_USERNAME%'
            password: '%TEST_DB_PASSWORD%'
            cleanup: true
            transaction: true
params:
    - config/params-local.php

1 个答案:

答案 0 :(得分:0)

Yii2模块在验收测试中对应用程序代码的执行没有影响。

不可能知道您的应用程序对数据库进行了哪些更改,因此您唯一的选择是从备份中还原数据库。

为了在测试前使数据库处于已知状态,您可以使用DB moduledump选项加载SQL文件,但不要在生产数据库中这样做。

相关问题