Skip to content

Commit c6c05b6

Browse files
authored
Fix issue where AbstractSchema::refresh() didn't completely clear cache (#1099)
1 parent 2705f80 commit c6c05b6

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
- New #1082: Add `QueryPartsInterface::addWithQuery()` method (@vjik)
174174
- Chg #1082: `QueryPartsInterface::withQuery()` method replace "WITH" clause instead of adding before (@vjik)
175175
- Enh #1092: Change the exceptions thrown to be more appropriate (@Tigrov)
176+
- Bug #1099: Fix an issue where `AbstractSchema::refresh()` didn't completely clear cache (@vjik)
176177

177178
## 1.3.0 March 21, 2024
178179

src/Schema/AbstractSchema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ public function refresh(): void
233233

234234
$this->tableNames = [];
235235
$this->tableMetadata = [];
236+
$this->schemaNames = [];
237+
$this->viewNames = [];
238+
$this->resultColumns = [];
236239
}
237240

238241
public function refreshTableSchema(string $name): void

tests/AbstractSchemaTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\TestCase;
88
use Yiisoft\Db\Constant\DataType;
9+
use Yiisoft\Db\Exception\NotSupportedException;
910
use Yiisoft\Db\Tests\Support\Assert;
1011
use Yiisoft\Db\Tests\Support\TestTrait;
1112

@@ -61,14 +62,21 @@ public function testGetDataType(): void
6162

6263
public function testRefresh(): void
6364
{
64-
$db = $this->getConnection();
65-
65+
$db = $this->getConnection(true);
6666
$schema = $db->getSchema();
67-
$schema->refresh();
6867

69-
$db->close();
68+
try {
69+
$this->assertNotEmpty($schema->getTableNames());
70+
$this->assertNotEmpty($schema->getViewNames());
71+
$this->assertNotEmpty($schema->getSchemaNames());
72+
} catch (NotSupportedException) {
73+
}
74+
75+
$schema->refresh();
7076

7177
$this->assertSame([], Assert::getPropertyValue($schema, 'tableMetadata'));
7278
$this->assertSame([], Assert::getPropertyValue($schema, 'tableNames'));
79+
$this->assertSame([], Assert::getPropertyValue($schema, 'schemaNames'));
80+
$this->assertSame([], Assert::getPropertyValue($schema, 'viewNames'));
7381
}
7482
}

0 commit comments

Comments
 (0)