FiftiN
FiftiN

Reputation: 797

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?

Upvotes: 4

Views: 4537

Answers (1)

Amirh
Amirh

Reputation: 473

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

Upvotes: 12

Related Questions