【问题标题】:Codeception with Yii1 enabled module启用 Yii1 模块的 Codeception
【发布时间】:2017-02-28 08:35:30
【问题描述】:

我正在使用 codeception 2.2.5 和 Yii 1.1.4 Yii1 模块有问题。我已经为功能和单元测试配置了它

这里是functional.suite.yml

class_name: FunctionalTester
modules:
    enabled:
        - Yii1:
            appPath: 'www/test.php'
            url: 'http://localhost/test.php'
            part: init
        - PhpBrowser:
            url: 'http://localhost/index-test.php'
        - \Helper\Functional
coverage:
    enabled: true
    remote: false

这是unit.suite.yml

class_name: UnitTester
modules:
    enabled:
        - Asserts
        - Yii1:
            appPath: 'www/test.php'
            url: 'http://localhost/test.php'
        - \Helper\Unit

当我单独运行测试时,一切正常。例如

php codecept.phar run functional --xml --html
php codecept.phar run unit --xml --html

当我一起奔跑时

php codecept.phar run --xml --html

它运行功能没有与 Yii1 模块相关的问题。它带来的单位是

[Codeception\Exception\ModuleConfigException]                     
  Yii1 module is not configured!                                    

  Couldn't load application config file www/test.php                
  Please provide application bootstrap file configured for testing

一起运行的主要目标是代码覆盖率。

【问题讨论】:

    标签: php unit-testing yii functional-testing codeception


    【解决方案1】:

    这是我的问题的答案:

    我创建了一个单独的模块 Yii1Ext(Yii1Ext.php),它扩展到 Yii1 模块:

    namespace Helper;
    
    use Codeception\Module\Yii1;
    
    class Yii1Ext extends Yii1
    {
        public function _initialize()
        {
            $this->config['appPath'] = FRONTEND.'/'.$this->config['appPath'];
            parent::_initialize();
        }
    }
    

    并且在配置文件中启用了 Yii1Ext 模块而不是 Yii1 模块

    class_name: FunctionalTester
    modules:
        enabled:
            - \Helper\Yii1Ext:
                appPath: 'www/test.php'
                url: 'http://localhost/test.php'
                part: init
            - PhpBrowser:
                url: 'http://localhost/'
    

    注意:确保 Yii 中所有定义的变量都由语句定义

    defined('ROOT_DIR') or define('ROOT_DIR', realpath(__DIR__ . '/../'));
    

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 2023-04-01
      • 2014-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多