For example, in the database there is a table tbl_identitydocument
, which is not linked with others:
CREATE TABLE [dbo].[tbl_identitydocument](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NOT NULL,
[FISID] [int] NULL,
CONSTRAINT [PK_tbl_identitydocument] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
This table corresponds to the model IdentityDocument.php
. In the model there is the validation of the fields, for it is written a simple Unit test.
The test fails with the error:
There was 1 error: [yii\base\InvalidParamException] Table not found: []
How to test models in Yii 2? Maybe I'm doing something wrong.
And for the test, and for the Web application I use the same database.
This is what is written in README.md:
Create yii2_advanced_tests database then update it by applying migrations: codeception/bin/yii migrate
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?..
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.