找不到代码接收Yii [英] Codeception not found Yii

查看:74
本文介绍了找不到代码接收Yii的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用codecept在Yii2项目中运行单元测试。并收到下一个错误:

I have tried to run unit tests in Yii2 project with using codecept. And received next error:

PHP Fatal error:  Class 'Yii' not found in /var/www/html/mysite/vendor/codeception/codeception/src/Codeception/Module/Yii2.php on line 77

这是我的单元。 suite.yml内容:

It's my unit.suite.yml content:

# Codeception Test Suite Configuration

# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: CodeGuy
modules:
    enabled: [CodeHelper, Yii2]
    config:
        Yii2:
            configFile: 'config/web.php'

有人知道问题出在哪里吗?

Does anyone know what the problem is?

推荐答案

首先请确保您已通过composer以标准方式安装了代码接收: codeception / codeception: *

First make sure that you have installed codeception the standard way which is through composer: "codeception/codeception":"*"

运行代码接收时,无需将其添加到unit.suite.yml即可加载Yii。只需更改您可以在rootfolder / tests /中找到的_bootstrap.php文件并添加以下行即可:

You don't need to add it to your unit.suite.yml to load Yii when you run codeception. Just change the _bootstrap.php file you can find at rootfolder/tests/ and add the following lines:

<?php

// This is global bootstrap for autoloading

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/console.php');
//
$application = new yii\console\Application( $config );

这篇关于找不到代码接收Yii的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆