I am using YII2 2.0.10, basic. It looks like it no longer uses yii-codeception. Those. The documentation on this page is invalid: http://www.yiiframework.com/doc-2.0/guide-test-fixtures.html
The problem is that I can not load the fixture into my test. I do it like this:
tests \ unit \ models \ 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); ... tests \ fixtures \ UserFixture.php
namespace tests\fixtures; use yii\test\ActiveFixture; class UserFixture extends ActiveFixture { public $modelClass = 'dektrium\user\models\User'; } Data is taken from tests \ fixtures \ data \ user.php
After running vendor / codeception / base / codecept run, I get
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 What am I doing wrong?