php - 尝试运行时出现代码错误 "Class Yii not found"

标签 php yii2 codeception

目前正在为我的学徒项目工作。我做了一些自动化测试。我通过运行和构建套件来初始化 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

执行以下操作: Do the following

关于php - 尝试运行时出现代码错误 "Class Yii not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45955411/

相关文章:

javascript - 我可以使用 Netbeans 7.3 来调试 PHP 脚本以响应 JSON 请求吗?

yii2 - yii2如何创建子模块

php - 在 Codeception 测试中循环访问页面上的链接

yii2 - 如何从 Yii2 的`ApiTester 实例中调用 `grabFixture()` 方法?

javascript - 页面加载时出现蓝屏

php - 在 xpath 中合并两个 DOMNodeLists

php - 使用 MySQL 计算唯一 IP 地址

php - Yii2 : Handling Assets For A custom theme

php - Yii2 执行sql时出错

mysql - Codeception DB模块异常