4

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?

5
  • It looks like namespace problem, BTW this path "/vendor/codeception/codeception/src/Codeception/Module/Yii2.php" looks strange for me. Do you run composer update? Commented Feb 11, 2015 at 12:26
  • Sorry, I have recreated project. And now I have problem with installation of codeception over composer stackoverflow.com/q/28455369/1035334 Commented Feb 11, 2015 at 13:20
  • @TomaszKane Ok, Yes, I do. But it has no effect:( Commented Feb 11, 2015 at 13:37
  • @TomaszKane I don't know wtf is this, but after I added line "class_exists("\\yii\Yii")" to vendor autoload file, the problem went away. Commented Feb 11, 2015 at 14:02
  • what does you web.php file says? Commented Aug 15, 2017 at 12:36

1 Answer 1

12

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 ); 
Sign up to request clarification or add additional context in comments.

2 Comments

I am doing the same as you suggested. Still I am getting the same error. I dont know what to write against configFile in my .yml file
howtobuildsoftware.com/index.php/how-do/Zfv/… - looks a bit familiar doesn't it..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.