使用Yii1实现Codeception

时间:2018-03-16 07:58:46

标签: php unit-testing yii codeception

我正在尝试为在Yii1中完成的项目进行单元测试。这些是我采取的步骤

添加了composer.json并添加了以下内容

{
    "require-dev": {
        "codeception/codeception": "2.3.*",
        "codeception/yii-bridge":"dev-master"
    }
}

并通过bootstrapping创建了完整的套装

在我的unit.suit.yml中,我添加了

- Yii1:
        appPath: '../index-test.php'
        url: 'http://localhost/pricingdb/index-test.php/'       

在我的index-test.php中我有

<?php

defined('DS') or define('DS', DIRECTORY_SEPARATOR);

$yii=dirname(__FILE__).'/../../yii-1.1.12.b600af/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/test.php';

defined('YII_DEBUG') or define('YII_DEBUG',true);

require_once($yii);
require_once __DIR__.DS.'vendor'.DS.'autoload.php';

return array(
       'class' => 'CWebApplication',
       'config' => $config,
);

在我的config / test.php中我有

<?php

return CMap::mergeArray(
                require(dirname(__FILE__) . '/main.php'), array(
            'components' => array(
                'request' => array(
                    'class' => 'CodeceptionHttpRequest'
                ),
            ),
                )
);

当我尝试使用以下命令从受保护的文件夹运行单元测试时

..\vendor\bin\codecept run unit

我收到以下消息

In Yii1.php line 173:

  Yii1 module is not configured!

  Codeception-Yii Bridge is not launched. In order to run tests you need to install https://github.com/Codeception/Yi
  iBridge Implement function 'launch_codeception_yii_bridge' to load all Codeception overrides

我在这里缺少什么?对于&#34;实现功能&#39; launch_codeception_yii_bridge&#39;是什么意思?加载所有Codeception覆盖&#34; ? 我该怎么做?

1 个答案:

答案 0 :(得分:1)

我添加了

require_once __DIR__.'/../../../../vendor/codeception/yii-bridge/yiit.php';

在Helper / Unit.php中它现在似乎有效。