I get this strange error when trying to run the unit test of the model.
Model:
<?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'),
];
}
}
Simple Unit test of the validation:
<?php
namespace tests\codeception\backend;
use tests\codeception\backend\unit\DbTestCase;
use backend\modules\persons\models\IdentityDocument;
class IdentityDocumentTest extends DbTestCase
{
/**
* @var \tests\codeception\backend\UnitTester
*/
protected $identityDocument;
protected function _before()
{
}
protected function _after()
{
}
// tests
public function testNameIsRequired()
{
$this->identityDocument = new IdentityDocument();
$this->identityDocument->Name = '';
\PHPUnit_Framework_Assert::AssertFalse($this->identityDocument->validate(array('Name')));
}
}
Full stacktrace:
Codeception PHP Testing Framework v2.2.0
Powered by PHPUnit 4.8.26 by Sebastian Bergmann and contributors.
[1mTests\codeception\backend.unit Tests (1) [22m-------------------
Modules: [32mAsserts, Db[39m
------------------------------------------------------------
[31;1mE[39;22m [35;1mIdentityDocumentTest:[39;22m Name is required
------------------------------------------------------------
Time: 6.19 seconds, Memory: 11.75MB
There was 1 error:
---------
1) [35;1mIdentityDocumentTest:[39;22m Name is required
[37;41;1m Test [39;49;22m unit\IdentityDocumentTest.php:testNameIsRequired
[37;41;1m [39;49;22m
[37;41;1m [yii\base\InvalidParamException] Table not found: [] [39;49;22m
[37;41;1m [39;49;22m
C:\projects\ais\vendor\yiisoft\yii2\db\Command.php:753
C:\projects\ais\vendor\yiisoft\yii2\test\InitDbFixture.php:94
C:\projects\ais\vendor\yiisoft\yii2\test\InitDbFixture.php:76
C:\projects\ais\vendor\yiisoft\yii2\test\FixtureTrait.php:114
C:\projects\ais\vendor\yiisoft\yii2-codeception\TestCase.php:85
C:\composer\vendor\phpunit\phpunit\src\Framework\TestCase.php:764
C:\composer\vendor\phpunit\phpunit\src\Framework\TestResult.php:612
C:\composer\vendor\phpunit\phpunit\src\Framework\TestCase.php:724
C:\composer\vendor\phpunit\phpunit\src\Framework\TestSuite.php:747
C:\composer\vendor\codeception\codeception\src\Codeception\PHPUnit\Runner.php:98
C:\composer\vendor\codeception\codeception\src\Codeception\SuiteManager.php:152
C:\composer\vendor\codeception\codeception\src\Codeception\Codecept.php:209
C:\composer\vendor\codeception\codeception\src\Codeception\Codecept.php:178
C:\composer\vendor\codeception\codeception\src\Codeception\Command\Run.php:329
C:\composer\vendor\codeception\codeception\src\Codeception\Command\Run.php:256
C:\composer\vendor\symfony\console\Command\Command.php:259
C:\composer\vendor\symfony\console\Application.php:844
C:\composer\vendor\symfony\console\Application.php:192
C:\composer\vendor\symfony\console\Application.php:123
C:\composer\vendor\codeception\codeception\src\Codeception\Application.php:103
C:\composer\vendor\codeception\codeception\codecept:33
[37;41mFAILURES![0m
[37;41mTests: 1[0m[37;41m, Assertions: 0[0m[37;41m, Errors: 1[0m[37;41m.[0m
What it might mean - "Table not found"? Which table? How can I test the model?