Skip to content

Commit 3a71619

Browse files
committed
Add more tests
1 parent 1516b12 commit 3a71619

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tests/unit/IssueFixTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,86 @@ private function deleteTableFor58CreateMigrationForColumnPositionChangeIfAFieldP
392392
{
393393
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%fruits}}')->execute();
394394
}
395+
396+
public function test58DeleteLastCol()
397+
{
398+
$deleteTable = function () {
399+
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%fruits}}')->execute();
400+
};
401+
$createTable = function () {
402+
Yii::$app->db->createCommand()->createTable('{{%fruits}}', [
403+
'id' => 'pk',
404+
'description' => 'text not null',
405+
'name' => 'text not null',
406+
])->execute();
407+
};
408+
$schema = <<<YAML
409+
openapi: 3.0.3
410+
info:
411+
title: 'test58DeleteLastCol'
412+
version: 1.0.0
413+
components:
414+
schemas:
415+
Fruit:
416+
type: object
417+
properties:
418+
id:
419+
type: integer
420+
description:
421+
type: string
422+
nullable: false
423+
paths:
424+
'/':
425+
get:
426+
responses:
427+
'200':
428+
description: OK
429+
YAML;
430+
$config = [
431+
'openApiPath' => 'data://text/plain;base64,'.base64_encode($schema),
432+
'generateUrls' => false,
433+
'generateModels' => false,
434+
'generateControllers' => false,
435+
'generateMigrations' => true,
436+
'generateModelFaker' => false,
437+
];
438+
$tmpConfigFile = Yii::getAlias("@runtime")."/tmp-config.php";
439+
file_put_contents($tmpConfigFile, '<?php return '.var_export($config, true).';');
440+
441+
$expected = <<<'PHP'
442+
<?php
443+
444+
/**
445+
* Table for Fruit
446+
*/
447+
class m200000_000000_change_table_fruits extends \yii\db\Migration
448+
{
449+
public function up()
450+
{
451+
$this->dropColumn('{{%fruits}}', 'name');
452+
}
453+
454+
public function down()
455+
{
456+
$this->addColumn('{{%fruits}}', 'name', $this->text()->notNull()->after('description'));
457+
}
458+
}
459+
460+
PHP;
461+
462+
foreach (['Mysql', 'Mariadb'] as $db) {
463+
$this->{"changeDbTo$db"}();
464+
$deleteTable();
465+
$createTable();
466+
467+
$dbStr = str_replace('db', '', strtolower($db));
468+
$this->runGenerator($tmpConfigFile, $dbStr);
469+
$this->runActualMigrations($dbStr, 1);
470+
$actual = file_get_contents(Yii::getAlias('@app').'/migrations_'.$dbStr.'_db/m200000_000000_change_table_fruits.php');
471+
$this->assertSame($expected, $actual);
472+
473+
$deleteTable();
474+
}
475+
FileHelper::unlink($tmpConfigFile);
476+
}
395477
}

0 commit comments

Comments
 (0)