yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

Class 'codeception\fixtures\XxxFixture' not found #12765

Closed tianmingxing closed 7 years ago

tianmingxing commented 7 years ago

I got the following error while I was running the test method:

PHP Fatal error:  Class 'codeception\fixtures\XxxFixture' not found in D:\PhpProjects\example\tests\codeception\unit\models\XxxTest.php on line 14
PHP Stack trace:
PHP   1. {main}() C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\codecept:0
PHP   2. Codeception\Application->run() C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\codecept:33
PHP   3. Symfony\Component\Console\Application->run() C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Application.php:103
PHP   4. Symfony\Component\Console\Application->doRun() C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Application.php:118
PHP   5. Symfony\Component\Console\Application->doRunCommand() C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Application.php:187
PHP   6. Symfony\Component\Console\Command\Command->run() C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Application.php:820
PHP   7. Codeception\Command\Run->execute() C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Command\Command.php:256
<?php

namespace codeception\fixtures;

use yii\test\ActiveFixture;

class XxxFixture extends ActiveFixture
{
    public $modelClass = 'app\models\Xxx';
}
<?php

namespace tests\codeception\unit\models;

use app\models\Xxx;
use codeception\fixtures\XxxFixture;
use yii\codeception\TestCase;

class XxxTest extends TestCase
{
    public function fixtures()
    {
        return [
            'profiles' => XxxFixture::className(),
        ];
    }
}
Julian-B90 commented 7 years ago

Hello xiaoxing598, wich version of codeception do you have installed?

tianmingxing commented 7 years ago

@Julian-B90 Yes, I'm sure.

>codecept --version
Codeception version 2.2.5
dynasource commented 7 years ago

the codeception namespace seems to be C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception

shouldnt you change the namespace to that one of your app.

tianmingxing commented 7 years ago

@dynasource I use the overall installation codeception, In the direction that you put forward, how should I change?

Julian-B90 commented 7 years ago

Sorry i have forget this.

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

Can you add you Question to the Forum?

dynasource commented 7 years ago

what is the path of XxxFixture and how did you generate it?

tianmingxing commented 7 years ago

@dynasource

I created this class in IDE, in accordance with the document requirement inherited from ActiveFixture

dynasource commented 7 years ago

what is the filepath of XxxFixture

tianmingxing commented 7 years ago

@dynasource D:\PhpProjects\example\tests\codeception\fixtures\XxxFixture.php D:\PhpProjects\example\tests\codeception\unit\fixtures\data\xxx.php

Julian-B90 commented 7 years ago
<?php

namespace tests\codeception\fixtures\;

use yii\test\ActiveFixture;

class XxxFixture extends ActiveFixture
{
    public $modelClass = 'app\models\Xxx';
}
dynasource commented 7 years ago

as you can see, your IDE has created your fixture inside your Application. You should update the configuration of your IDE to match with the paths in your Application. @Julian-B90 shows in his answer the namespace which should be working.

tianmingxing commented 7 years ago

@Julian-B90 @dynasource Thank you very much for two big bull help, really because of the namespace problem, I follow the example of Julian-B90 to do, found that the problem is solved. Thank you very much.