尝试运行时出现代码接收错误“Class Yii not found”

Kyl*_*yle 4 php yii2 codeception

目前正在从事一个学徒项目。我做了一些自动化测试。我通过运行和构建套件来初始化代码接收

codecept bootstrap
codecept build
Run Code Online (Sandbox Code Playgroud)

这两个命令按预期工作,但是当我尝试运行测试时,我得到了

FATAL ERROR. TESTS NOT FINISHED.
Class 'Yii' not found 
in /srv/http/blog/vendor/codeception/codeception/src/Codeception/Module/Yii2.php:242
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?我查看了 Yii 和 Codeceptions 文档,但找不到解决方案。

更新 新的错误消息

FATAL ERROR. TESTS NOT FINISHED.
Class 'Yii' not found 
in /srv/http/blog/vendor/yiisoft/yii2/helpers/BaseUrl.php:129
Run Code Online (Sandbox Code Playgroud)

Neb*_*sar 5

就我而言,该_bootstrap.php文件无法正确加载。
为了解决这个问题,我将以下内容添加到我的codeception.yml

3.0 之前

settings:
    bootstrap: _bootstrap.php
    memory_limit: 1024M
    colors: true
Run Code Online (Sandbox Code Playgroud)

后3.0

 bootstrap: _bootstrap.php
 settings:        
    memory_limit: 1024M
    colors: true
Run Code Online (Sandbox Code Playgroud)

真的不知道颜色有什么作用,但它对我有用。这也是我的_bootstrap.php文件,提供了一些对此的见解。

使用应用程序\组件\助手;

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 );
Run Code Online (Sandbox Code Playgroud)

最后两行用于加载您的 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
Run Code Online (Sandbox Code Playgroud)

请执行下列操作: 请执行下列操作