YII2 Codeception - 创建夹具。 [错误] Class' tests \ fixtures \ UserFixture'未找到

时间:2016-12-22 23:18:44

标签: yii2 phpunit codeception

我使用YII2 2.0.10,基本。它似乎不再使用yii-codeception模块了。因此,此页面中的文档不是实际的: http://www.yiiframework.com/doc-2.0/guide-test-fixtures.html

我的问题是我无法在测试中加载夹具。 我用这种方式:

测试\单元\模型\ UserTest.php

<?php
namespace tests\models;
use app\models\User;
use tests\fixtures\UserFixture;

class UserTest extends \Codeception\Test\Unit
{
    public function testFindUserById()
    {
        // load fixtures
        $this->tester->haveFixtures([
            'user' => [
                'class' => UserFixture::className(),
                // fixture data located in tests/_data/user.php
                'dataFile' => codecept_data_dir() . 'user.php'
            ]
        ]);
        // get first user from fixtures
        $this->tester->grabFixture('user', 0);
        ...

测试\夹具\ UserFixture.php

namespace tests\fixtures;

use yii\test\ActiveFixture;

class UserFixture extends ActiveFixture
{
    public $modelClass = 'dektrium\user\models\User';
}

从tests \ fixtures \ data \ user.php

返回一些数据

vendor / codeception / base / codecept运行之后

2) UserTest: Find user by id
 Test  tests/unit/models/UserTest.php:testFindUserById

  [Error] Class 'tests\_fixtures\UserFixture' not found

#1  tests\models\UserTest->testFindUserById

我做错了什么?

0 个答案:

没有答案