Skip to content

Commit 26c8a26

Browse files
committed
Fix failing tests
1 parent e422b00 commit 26c8a26

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

tests/DbTestCase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use cebe\yii2openapi\generator\ApiGenerator;
66
use Yii;
7+
use yii\db\IndexConstraint;
78
use yii\di\Container;
89
use yii\db\mysql\Schema as MySqlSchema;
910
use yii\db\pgsql\Schema as PgSqlSchema;
@@ -192,4 +193,18 @@ protected function dropFkIfExists(string $table, string $fk): void
192193
Yii::$app->db->createCommand()->dropForeignKey($fk, $table)->execute();
193194
}
194195
}
196+
197+
protected function indexExists(string $indexName): bool
198+
{
199+
$indices = Yii::$app->db->schema->schemaIndexes;
200+
foreach ($indices as $subIndices) {
201+
foreach ($subIndices as $index) {
202+
/** @var IndexConstraint $index */
203+
if ($index->name === $indexName) {
204+
return true;
205+
}
206+
}
207+
}
208+
return false;
209+
}
195210
}

tests/specs/issue_fix/3_bug_add_remove_property_and_at_the_same_time_change_it_at_x_indexes/mysql/models/base/Address.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/postgres_custom/migrations_pgsql_db/m200000_000000_change_table_v3_pgcustom.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class m200000_000000_change_table_v3_pgcustom extends \yii\db\Migration
77
{
88
public function safeUp()
99
{
10-
$this->createIndex('v3_pgcustom_search_gin_index', '{{%v3_pgcustom}}', 'search', 'gin(to_tsvector(\'english\', status))');
10+
$this->createIndex('v3_pgcustom_search_gin_index', '{{%v3_pgcustom}}', 'to_tsvector(\'english\', search::text)', 'gin');
1111
$this->alterColumn('{{%v3_pgcustom}}', 'json1', "SET NOT NULL");
1212
$this->alterColumn('{{%v3_pgcustom}}', 'json1', "SET DEFAULT '[]'");
1313
$this->alterColumn('{{%v3_pgcustom}}', 'json2', "SET NOT NULL");
@@ -18,7 +18,6 @@ public function safeUp()
1818
$this->alterColumn('{{%v3_pgcustom}}', 'json4', "SET DEFAULT '{\"foo\":\"bar\",\"bar\":\"baz\"}'");
1919
$this->alterColumn('{{%v3_pgcustom}}', 'status', "SET DEFAULT 'draft'");
2020
$this->alterColumn('{{%v3_pgcustom}}', 'status_x', "SET DEFAULT 'draft'");
21-
$this->createIndex('v3_pgcustom_search_gin_index', '{{%v3_pgcustom}}', 'to_tsvector(\'english\', search::text)', 'gin');
2221
}
2322

2423
public function safeDown()

tests/unit/IssueFixTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ public function test158BugGiiapiGeneratedRulesEnumWithTrim()
547547
// https://github.com/php-openapi/yii2-openapi/issues/3
548548
public function test3BugAddRemovePropertyAndAtTheSameTimeChangeItAtXIndexes()
549549
{
550+
$this->dropTestTableFor3BugAddRemovePropertyAndAtTheSameTimeChangeItAtXIndexes();
550551
$this->createTestTableFor3BugAddRemovePropertyAndAtTheSameTimeChangeItAtXIndexes();
551552
$testFile = Yii::getAlias("@specs/issue_fix/3_bug_add_remove_property_and_at_the_same_time_change_it_at_x_indexes/index.php");
552553
$this->runGenerator($testFile);
@@ -574,8 +575,10 @@ private function createTestTableFor3BugAddRemovePropertyAndAtTheSameTimeChangeIt
574575

575576
private function dropTestTableFor3BugAddRemovePropertyAndAtTheSameTimeChangeItAtXIndexes()
576577
{
577-
Yii::$app->db->createCommand()->dropIndex('addresses_shortName_postalCode_key', '{{%addresses}}')->execute();
578-
Yii::$app->db->createCommand()->dropTable('{{%addresses}}')->execute();
578+
if ($this->indexExists('addresses_shortName_postalCode_key')) {
579+
Yii::$app->db->createCommand()->dropIndex('addresses_shortName_postalCode_key', '{{%addresses}}')->execute();
580+
}
581+
Yii::$app->db->createCommand('DROP TABLE IF EXISTS {{%addresses}}')->execute();
579582
}
580583

581584
// https://github.com/php-openapi/yii2-openapi/issues/29

0 commit comments

Comments
 (0)