Skip to content

Commit 353f61e

Browse files
committed
Fix failing test: IssueFixTest::testCreateMigrationForDropTable132
1 parent 25063ca commit 353f61e

File tree

9 files changed

+56
-10
lines changed

9 files changed

+56
-10
lines changed

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Animal.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**
6-
*
10+
* This is the model class for table "the_animal_table_name".
711
*
812
* @property integer $id
913
* @property string $name

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Bigpk.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**
6-
*
10+
* This is the model class for table "bigpks".
711
*
812
* @property integer $id
913
* @property string $name

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Foo.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Fruit.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**
6-
*
10+
* This is the model class for table "fruits".
711
*
812
* @property integer $id
913
* @property string $name

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Mango.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**
6-
*
10+
* This is the model class for table "the_mango_table_name".
711
*
812
* @property integer $id
913
* @property string $name

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Pristine.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**
6-
*
10+
* This is the model class for table "pristines".
711
*
812
* @property integer $id
913
* @property string $name

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Ubigpk.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**
6-
*
10+
* This is the model class for table "ubigpks".
711
*
812
* @property string $id
913
* @property string $name

tests/specs/issue_fix/132_create_migration_for_drop_table/mysql/models/base/Upk.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
37
namespace app\models\base;
48

59
/**
6-
*
10+
* This is the model class for table "upks".
711
*
812
* @property integer $id
913
* @property string $name

tests/unit/IssueFixTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public function testCreateMigrationForDropTable132IndependentTablesDropSort()
278278
public function testCreateMigrationForDropTable132()
279279
{
280280
$testFile = Yii::getAlias("@specs/issue_fix/132_create_migration_for_drop_table/132_create_migration_for_drop_table.php");
281+
$this->deleteTablesForCreateMigrationForDropTable132();
281282
$this->createTablesForCreateMigrationForDropTable132();
282283
$this->runGenerator($testFile);
283284
$this->runActualMigrations('mysql', 8);
@@ -343,16 +344,29 @@ private function createTablesForCreateMigrationForDropTable132()
343344

344345
private function deleteTablesForCreateMigrationForDropTable132()
345346
{
346-
Yii::$app->db->createCommand()->dropForeignKey('name', '{{%pristines}}')->execute();
347+
$tableSchema = Yii::$app->db->schema->getTableSchema('{{%pristines}}');
348+
if ($tableSchema && array_key_exists('name', $tableSchema->foreignKeys)) {
349+
Yii::$app->db->createCommand()->dropForeignKey('name', '{{%pristines}}')->execute();
350+
}
351+
347352
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%pristines}}')->execute();
348-
Yii::$app->db->createCommand()->dropForeignKey('name2', '{{%fruits}}')->execute();
353+
354+
$tableSchema = Yii::$app->db->schema->getTableSchema('{{%fruits}}');
355+
if ($tableSchema && array_key_exists('name2', $tableSchema->foreignKeys)) {
356+
Yii::$app->db->createCommand()->dropForeignKey('name2', '{{%fruits}}')->execute();
357+
}
358+
349359
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%fruits}}')->execute();
350360

351361
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%upks}}')->execute();
352362
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%bigpks}}')->execute();
353363
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%ubigpks}}')->execute();
354364

355-
Yii::$app->db->createCommand()->dropForeignKey('animal_fruit_fk', '{{%the_mango_table_name}}')->execute();
365+
$tableSchema = Yii::$app->db->schema->getTableSchema('{{%the_mango_table_name}}');
366+
if ($tableSchema && array_key_exists('animal_fruit_fk', $tableSchema->foreignKeys)) {
367+
Yii::$app->db->createCommand()->dropForeignKey('animal_fruit_fk', '{{%the_mango_table_name}}')->execute();
368+
}
369+
356370
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%the_mango_table_name}}')->execute();
357371
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%the_animal_table_name}}')->execute();
358372
}

0 commit comments

Comments
 (0)