目前正在为我的学徒项目工作。我做了一些自动化测试。我通过运行和构建套件来初始化 codeception
codecept bootstrap
codecept build
这 2 个命令按预期工作,但是当我尝试运行测试时,我得到了
FATAL ERROR. TESTS NOT FINISHED.
Class 'Yii' not found
in /srv/http/blog/vendor/codeception/codeception/src/Codeception/Module/Yii2.php:242
有什么想法吗?我查看了 Yii 和 Codeceptions 的文档,但找不到解决方案。
更新 新的错误信息
FATAL ERROR. TESTS NOT FINISHED.
Class 'Yii' not found
in /srv/http/blog/vendor/yiisoft/yii2/helpers/BaseUrl.php:129
最佳答案
在我的例子中,_bootstrap.php
文件无法正确加载。
为了解决这个问题,我在我的 codeception.yml
中添加了以下内容:
3.0 之前
settings:
bootstrap: _bootstrap.php
memory_limit: 1024M
colors: true
后 3.0
bootstrap: _bootstrap.php
settings:
memory_limit: 1024M
colors: true
我真的不知道颜色有什么作用,但它对我有用。
这也是我的 _bootstrap.php
文件,其中包含一些关于此的见解。
使用 app\components\Helpers;
define('YII_ENV', 'test');
require_once __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
require __DIR__ .'/../vendor/autoload.php';
$config = require(__DIR__ . '/../config/console.test.php');
//
$application = new yii\console\Application( $config );
最后两行用于加载 Yii 类。 希望这对你有用!
3.0 及更高版本的更新
来自 http://phptest.club/t/bootstrap-deprecations-in-3-0/2196
如果您收到此消息:
DEPRECATION: 'settings: bootstrap: _bootstrap.php' option is deprecated! Replace it with: 'bootstrap: _bootstrap.php' (not under settings section). See http://phptest.club/t/bootstrap-deprecations-in-3-0/2196
DEPRECATION: Bootstrap file (_bootstrap.php) is defined in configuration but can't be loaded. Disable 'settings: bootstrap:' configuration to remove this message
关于php - 尝试运行时出现代码错误 "Class Yii not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45955411/