Migrating Yii 2 for a test database

I do not see a clear way to do this, although I see that it is repeated several times in the documentation, in particular:

Use the yii migration tool to upgrade the test database to the latest version;

found at http://www.yiiframework.com/doc-2.0/guide-test-fixture.html#summary (just to give an example)

What happens is that no matter how I configure _console.php and _config.php in my tests/unit folder, if I run the migration tool, select the main db application:

 $ cd tests/unit $ ../../yii migrate/up Yii Migration Tool (based on Yii v2.0.0-dev) No new migration found. Your system is up-to-date. 

And yes, the test database is configured correctly (running the tests will cause an error saying that there are no tables). I obviously can create the db structure myself, but it all relates to how this function works as it should.

I am currently using the Basic application installed through the composer.

+5
source share
3 answers

[edit] updated answer to reflect current version of Yii2

Just post the correct answer when I found it myself, and I feel a little silly, like it was under my eyes.

There is another yii command line in the test folders directory, which means you can easily do:

 $ cd tests/codeception/bin $ chmod a+x yii $ yii migrate/up 

and it automatically uses the database specified in tests/codeception/config/config.php .

Enjoy

+14
source

Just using yii_test migrate for Yii2.

+5
source

To apply migrations for the test database in Yii2, run this command in the project directory:

 php tests/bin/yii migrate 
0
source

Source: https://habr.com/ru/post/1200311/


All Articles