Skip to content

Commit 3bf289a

Browse files
Remove getCacheKey() to ConnectionInterface::class. (#243)
1 parent c8de2b1 commit 3bf289a

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/Schema.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
use Yiisoft\Db\Constraint\Constraint;
1010
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
1111
use Yiisoft\Db\Constraint\IndexConstraint;
12+
use Yiisoft\Db\Driver\PDO\PdoAbstractSchema;
1213
use Yiisoft\Db\Exception\Exception;
1314
use Yiisoft\Db\Exception\InvalidArgumentException;
1415
use Yiisoft\Db\Exception\InvalidConfigException;
1516
use Yiisoft\Db\Exception\NotSupportedException;
1617
use Yiisoft\Db\Expression\Expression;
1718
use Yiisoft\Db\Helper\ArrayHelper;
18-
use Yiisoft\Db\Schema\AbstractSchema;
1919
use Yiisoft\Db\Schema\Builder\ColumnInterface;
2020
use Yiisoft\Db\Schema\ColumnSchemaInterface;
2121
use Yiisoft\Db\Schema\TableSchemaInterface;
@@ -73,7 +73,7 @@
7373
* array{cid:string, name:string, type:string, notnull:string, dflt_value:string|null, pk:string}
7474
* >
7575
*/
76-
final class Schema extends AbstractSchema
76+
final class Schema extends PdoAbstractSchema
7777
{
7878
/**
7979
* @var array Mapping from physical column types (keys) to abstract column types (values).
@@ -695,7 +695,7 @@ protected function findViewNames(string $schema = ''): array
695695
*/
696696
protected function getCacheKey(string $name): array
697697
{
698-
return array_merge([self::class], $this->db->getCacheKey(), [$this->getRawTableName($name)]);
698+
return array_merge([self::class], $this->generateCacheKey(), [$this->getRawTableName($name)]);
699699
}
700700

701701
/**
@@ -707,6 +707,6 @@ protected function getCacheKey(string $name): array
707707
*/
708708
protected function getCacheTag(): string
709709
{
710-
return md5(serialize(array_merge([self::class], $this->db->getCacheKey())));
710+
return md5(serialize(array_merge([self::class], $this->generateCacheKey())));
711711
}
712712
}

tests/SchemaTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
use JsonException;
88
use Throwable;
9+
use Yiisoft\Db\Connection\ConnectionInterface;
910
use Yiisoft\Db\Constraint\CheckConstraint;
1011
use Yiisoft\Db\Exception\Exception;
1112
use Yiisoft\Db\Exception\InvalidConfigException;
1213
use Yiisoft\Db\Exception\NotSupportedException;
14+
use Yiisoft\Db\Sqlite\Schema;
1315
use Yiisoft\Db\Sqlite\Tests\Support\TestTrait;
1416
use Yiisoft\Db\Tests\Common\CommonSchemaTest;
17+
use Yiisoft\Db\Tests\Support\DbHelper;
1518

1619
/**
1720
* @group sqlite
@@ -315,4 +318,15 @@ public function testWorkWithPrimaryKeyConstraint(): void
315318

316319
parent::testWorkWithPrimaryKeyConstraint();
317320
}
321+
322+
public function testNotConnectionPDO(): void
323+
{
324+
$db = $this->createMock(ConnectionInterface::class);
325+
$schema = new Schema($db, DbHelper::getSchemaCache(), 'system');
326+
327+
$this->expectException(NotSupportedException::class);
328+
$this->expectExceptionMessage('Only PDO connections are supported.');
329+
330+
$schema->refreshTableSchema('customer');
331+
}
318332
}

0 commit comments

Comments
 (0)