Skip to content

Resolve: Bug: add/remove property and at the same time change it at x-indexes: #3 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Compare files in test
  • Loading branch information
SOHELAHMED7 committed Jun 27, 2024
commit a67e14afba8e34846cfe8f3fa93ad73e33bb66e0
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* Table for Address
*/
class m200000_000000_change_table_addresses extends \yii\db\Migration
{
public function up()
{
$this->addColumn('{{%addresses}}', 'postCode', $this->string(64)->null()->defaultValue(null));
$this->dropIndex('addresses_shortName_postalCode_key', '{{%addresses}}');
$this->createIndex('addresses_shortName_postCode_key', '{{%addresses}}', ["shortName", "postCode"], true);
$this->dropColumn('{{%addresses}}', 'postalCode');
}

public function down()
{
$this->addColumn('{{%addresses}}', 'postalCode', $this->string(64)->null()->defaultValue(null));
$this->dropIndex('addresses_shortName_postCode_key', '{{%addresses}}');
$this->createIndex('addresses_shortName_postalCode_key', '{{%addresses}}', ["shortName", "postalCode"], true);
$this->dropColumn('{{%addresses}}', 'postCode');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace app\models;

class Address extends \app\models\base\Address
{


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace app\models\base;

/**
* desc
*
* @property int $id
* @property string $name
* @property string $shortName
* @property string $postCode
*
*/
abstract class Address extends \yii\db\ActiveRecord
{
public static function tableName()
{
return '{{%addresses}}';
}

public function rules()
{
return [
'trim' => [['name', 'shortName', 'postCode'], 'trim'],
'shortName_postCode_unique' => [['shortName', 'postCode'], 'unique', 'targetAttribute' => [
'shortName',
'postCode',
]],
'name_string' => [['name'], 'string', 'max' => 64],
'shortName_string' => [['shortName'], 'string', 'max' => 64],
'postCode_string' => [['postCode'], 'string', 'max' => 64],
];
}
}
15 changes: 7 additions & 8 deletions tests/unit/IssueFixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,17 @@ public function test158BugGiiapiGeneratedRulesEnumWithTrim()
// https://github.com/php-openapi/yii2-openapi/issues/3
public function test3BugAddRemovePropertyAndAtTheSameTimeChangeItAtXIndexes()
{
// $this->changeDbToMariadb();
$this->createTestTableFor3BugAddRemovePropertyAndAtTheSameTimeChangeItAtXIndexes();
$testFile = Yii::getAlias("@specs/issue_fix/3_bug_add_remove_property_and_at_the_same_time_change_it_at_x_indexes/index.php");
$this->runGenerator($testFile);
$this->runActualMigrations('mysql', 1);
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
// 'recursive' => true,
// ]);
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/158_bug_giiapi_generated_rules_enum_with_trim/maria"), [
// 'recursive' => true,
// ]);
// $this->checkFiles($actualFiles, $expectedFiles);
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
'recursive' => true,
]);
$expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/3_bug_add_remove_property_and_at_the_same_time_change_it_at_x_indexes/mysql"), [
'recursive' => true,
]);
$this->checkFiles($actualFiles, $expectedFiles);
$this->dropTestTableFor3BugAddRemovePropertyAndAtTheSameTimeChangeItAtXIndexes();
}

Expand Down
Loading