As I understand it, by using the migration I need to replicate the structure of the industrial database to the test database and then use fixtures to populate created by using migrations tables? And only after that Unit testing of models will be possible?..
I copied the structure of the industrial database to the test database, changed the data source name in config.php and in main-local.php. However, the error appears again.
Here is a simple “smoke test” that I’m trying to run:
<?php
namespace tests\codeception\backend;
use tests\codeception\backend\unit\DbTestCase;
use backend\modules\persons\models\IdentityDocument;
class SmokeTest extends DbTestCase
{
/**
* @var IdentityDocument
*/
protected $identityDocument;
protected function _before()
{
$this->identityDocument = new IdentityDocument();
}
protected function _after() { }
// tests
public function testMe() { }
}
The model itself:
<?php
namespace backend\modules\persons\models;
use Yii;
/**
* This is the model class for table "{{%identitydocument}}".
*
* @property integer $ID
* @property string $Name
* @property integer $FISID
*/
class IdentityDocument extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%identitydocument}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['Name'], 'required'],
[['Name'], 'string'],
[['FISID'], 'integer']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'ID' => Module::t('ML', 'ID'),
'Name' => Module::t('ML', 'Name'),
'FISID' => Module::t('ML', 'FISID'),
];
}
}
Solved. If in the Unit test fixtures are not used, then it is possible to extend the TestCase class instead of DbTestCase, otherwise the fixture loader will cause errors.