V
V
Vocler2019-07-08 17:33:56
Yii
Vocler, 2019-07-08 17:33:56

Why do I need a database for tests in Yii2?

I am familiar with testing in Yii2. I download the usual basic template, I try to run the tests, I get

Exception (Database Exception) 'yii\db\Exception' with message 'SQLSTATE[HY000] [1044] Access denied for user 'yii2'@'%' to database 'yii2_basic_tests''
The error occurs both through the console ( codecept run) and through the web ( index-test.php).
Apparently, the connection to the database in config/test.phpand is incorrectly configured config/db_test.php.
I tried to find the answer in the yii manual , but it doesn't say anything about the test database. I tried to find it in the Codeception documentation, but I couldn't either. I watched a video on YouTube, where the tests immediately ran normally without configuring the database ..
Actually, the question is: what should be specified in config/db_test.php?
1) The same database that I use in the "normal" operation of the application? What for then the separate file is necessary? Is it possible to pull data from config/db.php?
2) The second DB specially created for tests? What then it should be for a DB? Should it be empty? Does it have to be a copy of the database for the "normal" operation of the application? Here I was very embarrassed that I could not find information about this "test" database. I will be grateful if you indicate the direction where to dig.
UPD : It's also interesting why a separate config is needed at all. config/test.php
After all, when testing, the conditions should be as close as possible to the "combat" ones. Why is it impossible to use the standard config for tests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2019-07-08
@Vocler

A test database is needed for test manipulations, you won’t delete and add in combat, make sales and issue documents? Or will you? ;) You will not send letters to real addresses?
Test database - base-imitation. Almost like a real one, but with worthless data. Test in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question