Codeception not found Yii

邮差的信 提交于 2019-12-23 11:57:34

问题


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

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?


回答1:


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

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 );


来源:https://stackoverflow.com/questions/28448166/codeception-not-found-yii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!