P
P
Pavel2017-02-27 16:40:10
Yii
Pavel, 2017-02-27 16:40:10

How to create independent migration for test base in YII2?

Actually a question. How to create your own migration for the test base, so that when you launch
yii migarte
it,
tests\bin\yii migrate
you can apply two different migrations. I guess it's possible to specify somewhere the path to the migrations folder for two different console applications?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-02-27
@Palych_tw

Good afternoon.
The path to the migration file can be specified like this
For tests it is better to use another database.
Here this question is considered, although this is not the only solution.
PS
Two more articles on testing, the configuration of tests is considered
once (article)
two (webinar)
PS
Here is an example of a fixture to fill the test base using the basic example.
Create a fixtures directory with a class in it

namespace app\fixtures;

use yii\test\ActiveFixture;

class AirportFixture extends ActiveFixture
{
    public $modelClass = 'app\modules\airlines\models\Airport'; // модель, с которой будет работать фикстура
    public $dataFile = '@app/fixtures/data/airport.php'; // путь к директории с фикстурой, располагаете в fixtures
}

Fixture content
return [
    ['airport_ru'=>'Аэропорт 1','airport_en'=>'Airport 1','iata_airport'=>'AR1','country_id'=>8,'city_id'=>8,'created_at'=>time(),'updated_at'=>time()],
    ['airport_ru'=>'Аэропорт 2','airport_en'=>'Airport 2','iata_airport'=>'AR2','country_id'=>9,'city_id'=>9,'created_at'=>time(),'updated_at'=>time()],
    ['airport_ru'=>'Аэропорт 3','airport_en'=>'Airport 3','iata_airport'=>'AR3','country_id'=>10,'city_id'=>10,'created_at'=>time(),'updated_at'=>time()],
    ['airport_ru'=>'Аэропорт 4','airport_en'=>'Airport 4','iata_airport'=>'AR4','country_id'=>11,'city_id'=>11,'created_at'=>time(),'updated_at'=>time()],
    ['airport_ru'=>'Аэропорт 5','airport_en'=>'Airport 5','iata_airport'=>'AR5','country_id'=>12,'city_id'=>12,'created_at'=>time(),'updated_at'=>time()],
    ['airport_ru'=>'Аэропорт 6','airport_en'=>'Airport 6','iata_airport'=>'AR6','country_id'=>13,'city_id'=>13,'created_at'=>time(),'updated_at'=>time()],
    ['airport_ru'=>'Аэропорт 7','airport_en'=>'Airport 7','iata_airport'=>'AR7','country_id'=>14,'city_id'=>14,'created_at'=>time(),'updated_at'=>time()],
];

In the console from the application directory, execute the command
, get a list of commands and execute
#load fixtures with different namespace.
yii fixture/load User --namespace=alias\my\custom\namespace\goes\here

Here are your fixtures loaded

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question