Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception not found Yii

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?

like image 224
FiftiN Avatar asked Dec 14 '22 16:12

FiftiN


1 Answers

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 );
like image 152
Amirh Avatar answered Dec 17 '22 05:12

Amirh