Skip to content
Prev Previous commit
Fix cebe#107
  • Loading branch information
SOHELAHMED7 committed Jan 3, 2023
commit 3fff89a4877dbe40ca946af6cb1fa2252c051126
5 changes: 3 additions & 2 deletions tests/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ protected function runActualMigrations(string $db = 'mysql', int $number = 2): v
$lastThird = count($upOutput) - 3;
$this->assertSame($upExitCode, 0);
$this->assertSame($upOutput[$last], 'Migrated up successfully.');
$this->assertSame($upOutput[$lastThird], $number.' migrations were applied.');
$this->assertSame($upOutput[$lastThird], $number.' '.(($number === 1) ? 'migration was' : 'migrations were').' applied.');
// 1 migration was applied.
// 2 migrations were applied.

// down
exec('cd tests; ./yii migrate-'.$db.'/down --interactive=0 '.$number, $downOutput, $downExitCode);
$last = count($downOutput) - 1;
$lastThird = count($downOutput) - 3;
$this->assertSame($downExitCode, 0);
$this->assertSame($downOutput[$last], 'Migrated down successfully.');
$this->assertSame($downOutput[$lastThird], $number.' migrations were reverted.');
$this->assertSame($downOutput[$lastThird], $number.' '.(($number === 1) ? 'migration was' : 'migrations were').' reverted.');

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

/**
* Table for Fruit
*/
class m200000_000000_change_table_fruits extends \yii\db\Migration
{
public function up()
{
$this->db->createCommand('ALTER TABLE {{%fruits}} ADD COLUMN test_emails json NOT NULL')->execute();
$this->alterColumn('{{%fruits}}', 'name', $this->text()->notNull());
}

public function down()
{
$this->alterColumn('{{%fruits}}', 'name', $this->string(255)->null()->defaultValue(null));
$this->dropColumn('{{%fruits}}', 'test_emails');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ components:
# default: '{}'

type: array
x-db-type: text[]
x-db-type: text
nullable: false
# default: '{}'

Expand Down
30 changes: 10 additions & 20 deletions tests/unit/IssueFixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,22 @@
// This class contains tests for various issues present at GitHub
class IssueFixTest extends DbTestCase
{
// TODO WIP resume from here
// fix https://github.com/cebe/yii2-openapi/issues/107
// 107_no_syntax_error
public function testMigrationsAreNotGeneratedWithSyntaxError()
{
// $testFile = Yii::getAlias("@specs/issue_fix/no_syntax_error_107/mysql/no_syntax_error_107.php");
// $this->runGenerator($testFile, 'mysql');
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
// 'recursive' => true,
// ]);
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/id_not_in_rules/app"), [
// 'recursive' => true,
// ]);
// $this->checkFiles($actualFiles, $expectedFiles);

// $this->changeDbToMariadb();
// $this->deleteTablesForNoSyntaxError107();
// $this->createTableForNoSyntaxError107();
// $testFile = Yii::getAlias("@specs/issue_fix/no_syntax_error_107/mysql/no_syntax_error_107.php");
// $this->runGenerator($testFile, 'maria');

$this->changeDbToPgsql();
$testFile = Yii::getAlias("@specs/issue_fix/no_syntax_error_107/mysql/no_syntax_error_107.php");
$this->deleteTablesForNoSyntaxError107();
$this->createTableForNoSyntaxError107();
$testFile = Yii::getAlias("@specs/issue_fix/no_syntax_error_107/mysql/no_syntax_error_107.php");
$this->runGenerator($testFile, 'pgsql');
$this->runGenerator($testFile, 'mysql');
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
'recursive' => true,
]);
$expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/no_syntax_error_107/mysql/app"), [
'recursive' => true,
]);
$this->checkFiles($actualFiles, $expectedFiles);
$this->runActualMigrations('mysql', 1);
}

private function deleteTablesForNoSyntaxError107()
Expand Down