Skip to content

Commit 84c9655

Browse files
committed
Change tests and add few more
1 parent 95db88f commit 84c9655

File tree

1 file changed

+171
-43
lines changed

1 file changed

+171
-43
lines changed

tests/unit/IssueFixTest.php

Lines changed: 171 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,11 @@ public function test58DeleteLast4Col()
713713
{
714714
$columns = [
715715
'id' => 'pk',
716-
'name' => 'text null',
717-
'description' => 'text null',
718-
'colour' => 'text null',
719-
'size' => 'text null',
720-
'col_6' => 'text null',
716+
'name' => 'bool null',
717+
'description' => 'bool null',
718+
'colour' => 'bool null',
719+
'size' => 'bool null',
720+
'col_6' => 'bool null',
721721
];
722722

723723
$schema = <<<YAML
@@ -733,7 +733,7 @@ public function test58DeleteLast4Col()
733733
id:
734734
type: integer
735735
name:
736-
type: string
736+
type: boolean
737737
paths:
738738
'/':
739739
get:
@@ -760,16 +760,79 @@ public function up()
760760
761761
public function down()
762762
{
763-
$this->addColumn('{{%fruits}}', 'description', $this->text()->null());
764-
$this->addColumn('{{%fruits}}', 'colour', $this->text()->null()->after('description'));
765-
$this->addColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
766-
$this->addColumn('{{%fruits}}', 'col_6', $this->text()->null());
763+
$this->addColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null));
764+
$this->addColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('description'));
765+
$this->addColumn('{{%fruits}}', 'size', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
766+
$this->addColumn('{{%fruits}}', 'col_6', $this->tinyInteger(1)->null()->defaultValue(null));
767767
}
768768
}
769769

770770
PHP;
771771

772-
$this->for58($schema, $expected, $columns, ['Mysql']);
772+
$this->for58($schema, $expected, $columns/*, ['Mysql']*/);
773+
}
774+
775+
public function test58DeleteFirst4Col()
776+
{
777+
$columns = [
778+
'name' => 'boolean null',
779+
'description' => 'boolean null',
780+
'colour' => 'boolean null',
781+
'size' => 'boolean null',
782+
'col_6' => 'boolean null',
783+
'col_7' => 'boolean null',
784+
];
785+
786+
$schema = <<<YAML
787+
openapi: 3.0.3
788+
info:
789+
title: 'test58MoveColumns'
790+
version: 1.0.0
791+
components:
792+
schemas:
793+
Fruit:
794+
type: object
795+
properties:
796+
col_6:
797+
type: boolean
798+
col_7:
799+
type: boolean
800+
paths:
801+
'/':
802+
get:
803+
responses:
804+
'200':
805+
description: OK
806+
YAML;
807+
808+
$expected = <<<'PHP'
809+
<?php
810+
811+
/**
812+
* Table for Fruit
813+
*/
814+
class m200000_000000_change_table_fruits extends \yii\db\Migration
815+
{
816+
public function up()
817+
{
818+
$this->dropColumn('{{%fruits}}', 'size');
819+
$this->dropColumn('{{%fruits}}', 'colour');
820+
$this->dropColumn('{{%fruits}}', 'description');
821+
$this->dropColumn('{{%fruits}}', 'name');
822+
}
823+
824+
public function down()
825+
{
826+
$this->addColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->first());
827+
$this->addColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
828+
$this->addColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('description'));
829+
$this->addColumn('{{%fruits}}', 'size', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
830+
}
831+
}
832+
833+
PHP;
834+
835+
$this->for58($schema, $expected, $columns/*, ['Mysql']*/);
773836
}
774837

775838
// ------------ Add
@@ -1099,10 +1162,10 @@ public function test58MoveLast2Col2PosUp()
10991162
{
11001163
$columns = [
11011164
'id' => 'pk',
1102-
'name' => 'text null',
1103-
'description' => 'text null',
1104-
'colour' => 'text null',
1105-
'size' => 'text null',
1165+
'name' => 'bool null',
1166+
'description' => 'bool null',
1167+
'colour' => 'bool null',
1168+
'size' => 'bool null',
11061169
];
11071170

11081171
$schema = <<<YAML
@@ -1118,13 +1181,13 @@ public function test58MoveLast2Col2PosUp()
11181181
id:
11191182
type: integer
11201183
colour:
1121-
type: string
1184+
type: boolean
11221185
size:
1123-
type: string
1186+
type: boolean
11241187
name:
1125-
type: string
1188+
type: boolean
11261189
description:
1127-
type: string
1190+
type: boolean
11281191
paths:
11291192
'/':
11301193
get:
@@ -1143,31 +1206,31 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
11431206
{
11441207
public function up()
11451208
{
1146-
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('id'));
1147-
$this->alterColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
1209+
$this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
1210+
$this->alterColumn('{{%fruits}}', 'size', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
11481211
}
11491212
11501213
public function down()
11511214
{
1152-
$this->alterColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
1153-
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('description'));
1215+
$this->alterColumn('{{%fruits}}', 'size', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
1216+
$this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('description'));
11541217
}
11551218
}
11561219

11571220
PHP;
11581221

1159-
$this->for58($schema, $expected, $columns, ['Mysql']);
1222+
$this->for58($schema, $expected, $columns/*, ['Mysql']*/);
11601223
}
11611224

1162-
// -----------
1225+
// ----------- Miscellaneous
11631226
public function test58Move1Add1Del1Col()
11641227
{
11651228
$columns = [
11661229
'id' => 'pk',
1167-
'name' => 'text null',
1168-
'description' => 'text null',
1169-
'colour' => 'text null',
1170-
'size' => 'text null',
1230+
'name' => 'boolean null',
1231+
'description' => 'boolean null',
1232+
'colour' => 'boolean null',
1233+
'size' => 'boolean null',
11711234
];
11721235

11731236
$schema = <<<YAML
@@ -1183,13 +1246,13 @@ public function test58Move1Add1Del1Col()
11831246
id:
11841247
type: integer
11851248
colour:
1186-
type: string
1249+
type: boolean
11871250
name:
1188-
type: string
1251+
type: boolean
11891252
description:
1190-
type: string
1253+
type: boolean
11911254
col_6:
1192-
type: string
1255+
type: boolean
11931256
paths:
11941257
'/':
11951258
get:
@@ -1208,28 +1271,93 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
12081271
{
12091272
public function up()
12101273
{
1211-
$this->addColumn('{{%fruits}}', 'col_6', $this->text()->null());
1274+
$this->addColumn('{{%fruits}}', 'col_6', $this->boolean()->null()->defaultValue(null));
12121275
$this->dropColumn('{{%fruits}}', 'size');
1213-
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('id'));
1214-
$this->alterColumn('{{%fruits}}', 'name', $this->text()->null()->after('colour'));
1215-
$this->alterColumn('{{%fruits}}', 'description', $this->text()->null()->after('name'));
1276+
$this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
1277+
$this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('colour'));
1278+
$this->alterColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
12161279
}
12171280
12181281
public function down()
12191282
{
1220-
$this->alterColumn('{{%fruits}}', 'description', $this->text()->null()->after('name'));
1221-
$this->alterColumn('{{%fruits}}', 'name', $this->text()->null()->after('id'));
1222-
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('description'));
1223-
$this->addColumn('{{%fruits}}', 'size', $this->text()->null());
1283+
$this->alterColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
1284+
$this->alterColumn('{{%fruits}}', 'name', $this->tinyInteger(1)->null()->defaultValue(null)->after('id'));
1285+
$this->alterColumn('{{%fruits}}', 'colour', $this->tinyInteger(1)->null()->defaultValue(null)->after('description'));
1286+
$this->addColumn('{{%fruits}}', 'size', $this->tinyInteger(1)->null()->defaultValue(null));
12241287
$this->dropColumn('{{%fruits}}', 'col_6');
12251288
}
12261289
}
12271290

12281291
PHP;
12291292

1230-
$this->for58($schema, $expected, $columns, ['Mysql']);
1293+
$this->for58($schema, $expected, $columns/*, ['Mysql']*/);
1294+
}
1295+
1296+
public function test58Add1Del1ColAtSamePosition()
1297+
{
1298+
$columns = [
1299+
'id' => 'pk',
1300+
'name' => 'bool null',
1301+
'description' => 'bool null',
1302+
'colour' => 'bool null',
1303+
'size' => 'bool null',
1304+
];
1305+
1306+
$schema = <<<YAML
1307+
openapi: 3.0.3
1308+
info:
1309+
title: 'test58MoveColumns'
1310+
version: 1.0.0
1311+
components:
1312+
schemas:
1313+
Fruit:
1314+
type: object
1315+
properties:
1316+
id:
1317+
type: integer
1318+
name:
1319+
type: boolean
1320+
description_new:
1321+
type: boolean
1322+
colour:
1323+
type: boolean
1324+
size:
1325+
type: boolean
1326+
paths:
1327+
'/':
1328+
get:
1329+
responses:
1330+
'200':
1331+
description: OK
1332+
YAML;
1333+
1334+
$expected = <<<'PHP'
1335+
<?php
1336+
1337+
/**
1338+
* Table for Fruit
1339+
*/
1340+
class m200000_000000_change_table_fruits extends \yii\db\Migration
1341+
{
1342+
public function up()
1343+
{
1344+
$this->addColumn('{{%fruits}}', 'description_new', $this->boolean()->null()->defaultValue(null)->after('name'));
1345+
$this->dropColumn('{{%fruits}}', 'description');
1346+
}
1347+
1348+
public function down()
1349+
{
1350+
$this->addColumn('{{%fruits}}', 'description', $this->tinyInteger(1)->null()->defaultValue(null)->after('name'));
1351+
$this->dropColumn('{{%fruits}}', 'description_new');
1352+
}
1353+
}
1354+
1355+
PHP;
1356+
1357+
$this->for58($schema, $expected, $columns);
12311358
}
12321359

1233-
// add 1 and del 1 col at same position
1360+
// TODO add tests cases:
12341361
// add 1 and del 1 col at different position
1362+
// add 2 and del 1 col at different positions
12351363
}

0 commit comments

Comments
 (0)