@@ -369,13 +369,14 @@ public function test58CreateMigrationForColumnPositionChange()
369369
370370 $ testFile = Yii::getAlias ("@specs/issue_fix/58_create_migration_for_column_position_change_if_a_field_position_is_changed_in_spec/index.php " );
371371 $ this ->runGenerator ($ testFile );
372- // $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
373- // 'recursive' => true,
374- // ]);
375- // $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/58_create_migration_for_column_position_change_if_a_field_position_is_changed_in_spec/mysql"), [
376- // 'recursive' => true,
377- // ]);
378- // $this->checkFiles($actualFiles, $expectedFiles);
372+ $ actualFiles = FileHelper::findFiles (Yii::getAlias ('@app ' ), [
373+ 'recursive ' => true ,
374+ ]);
375+ $ expectedFiles = FileHelper::findFiles (Yii::getAlias ("@specs/issue_fix/58_create_migration_for_column_position_change_if_a_field_position_is_changed_in_spec/mysql " ), [
376+ 'recursive ' => true ,
377+ ]);
378+ $ this ->checkFiles ($ actualFiles , $ expectedFiles );
379+ $ this ->runActualMigrations ('mysql ' , 1 );
379380 $ this ->deleteTableFor58CreateMigrationForColumnPositionChange ();
380381 }
381382
@@ -393,19 +394,19 @@ private function deleteTableFor58CreateMigrationForColumnPositionChange()
393394 Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%fruits}} ' )->execute ();
394395 }
395396
396- private function for58 ($ schema , $ expected )
397+ private function for58 ($ schema , $ expected , $ columns = [
398+ 'id ' => 'pk ' ,
399+ 'name ' => 'text not null ' ,
400+ 'description ' => 'text not null ' ,
401+ 'colour ' => 'text not null ' ,
402+ 'size ' => 'text not null ' ,
403+ ])
397404 {
398405 $ deleteTable = function () {
399406 Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%fruits}} ' )->execute ();
400407 };
401- $ createTable = function () {
402- Yii::$ app ->db ->createCommand ()->createTable ('{{%fruits}} ' , [
403- 'id ' => 'pk ' ,
404- 'name ' => 'text not null ' ,
405- 'description ' => 'text not null ' ,
406- 'colour ' => 'text not null ' ,
407- 'size ' => 'text not null ' ,
408- ])->execute ();
408+ $ createTable = function () use ($ columns ) {
409+ Yii::$ app ->db ->createCommand ()->createTable ('{{%fruits}} ' , $ columns )->execute ();
409410 };
410411
411412 $ config = [
@@ -426,15 +427,16 @@ private function for58($schema, $expected)
426427
427428 $ dbStr = str_replace ('db ' , '' , strtolower ($ db ));
428429 $ this ->runGenerator ($ tmpConfigFile , $ dbStr );
429- $ this ->runActualMigrations ($ dbStr , 1 );
430430 $ actual = file_get_contents (Yii::getAlias ('@app ' ) . '/migrations_ ' . $ dbStr . '_db/m200000_000000_change_table_fruits.php ' );
431431 $ this ->assertSame ($ expected , $ actual );
432+ $ this ->runActualMigrations ($ dbStr , 1 );
432433
433434 $ deleteTable ();
434435 }
435436 FileHelper::unlink ($ tmpConfigFile );
436437 }
437438
439+ // ------------ Delete
438440 public function test58DeleteLastCol ()
439441 {
440442 $ schema = <<<YAML
@@ -707,7 +709,7 @@ public function down()
707709 $ this ->for58 ($ schema , $ expected );
708710 }
709711
710- // ------------
712+ // ------------ Add
711713 public function test58AddAColAtLastPos ()
712714 {
713715 // default position is last so no `AFTER` needed
@@ -1028,4 +1030,83 @@ public function down()
10281030
10291031 $ this ->for58 ($ schema , $ expected );
10301032 }
1033+
1034+ // ------------ Just move columns
1035+ public function test58MoveColumns ()
1036+ {
1037+ $ columns = [
1038+ 'id ' => 'pk ' ,
1039+ 'name ' => 'text null ' ,
1040+ 'description ' => 'text null ' ,
1041+ 'colour ' => 'text null ' ,
1042+ 'size ' => 'text null ' ,
1043+ 'col_6 ' => 'text null ' ,
1044+ 'col_7 ' => 'text null ' ,
1045+ 'col_8 ' => 'text null ' ,
1046+ 'col_9 ' => 'text null ' ,
1047+
1048+ ];
1049+
1050+ $ schema = <<<YAML
1051+ openapi: 3.0.3
1052+ info:
1053+ title: 'test58MoveColumns'
1054+ version: 1.0.0
1055+ components:
1056+ schemas:
1057+ Fruit:
1058+ type: object
1059+ properties:
1060+ id:
1061+ type: integer
1062+ colour:
1063+ type: string
1064+ size:
1065+ type: string
1066+ name:
1067+ type: string
1068+ description:
1069+ type: string
1070+ col_6:
1071+ type: string
1072+ col_7:
1073+ type: string
1074+ col_8:
1075+ type: string
1076+ col_9:
1077+ type: string
1078+
1079+ paths:
1080+ '/':
1081+ get:
1082+ responses:
1083+ '200':
1084+ description: OK
1085+ YAML ;
1086+
1087+ $ expected = <<<'PHP'
1088+ <?php
1089+
1090+ /**
1091+ * Table for Fruit
1092+ */
1093+ class m200000_000000_change_table_fruits extends \yii\db\Migration
1094+ {
1095+ public function up()
1096+ {
1097+ $this->alterColumn('{{%fruits}}', 'colour', $this->text()->notNull()->after('id'));
1098+ $this->alterColumn('{{%fruits}}', 'size', $this->text()->notNull()->after('colour'));
1099+ }
1100+
1101+ public function down()
1102+ {
1103+ $this->alterColumn('{{%fruits}}', 'size', $this->text()->notNull()->after('colour'));
1104+ $this->alterColumn('{{%fruits}}', 'colour', $this->text()->notNull()->after('description'));
1105+ }
1106+ }
1107+
1108+ PHP;
1109+
1110+ $ this ->for58 ($ schema , $ expected , $ columns );
1111+ }
10311112}
0 commit comments