From cd145f1fc20c610b47f22ea4adc5c51851dad32d Mon Sep 17 00:00:00 2001 From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com> Date: Wed, 5 Apr 2023 02:50:33 -0400 Subject: [PATCH] Remove `getCacheKey()` to `ConnectionInterface::class`. (#276) --- src/Schema.php | 10 +++++----- tests/SchemaTest.php | 14 +++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Schema.php b/src/Schema.php index 1cf1e3dd..563a7257 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -9,15 +9,15 @@ use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Constraint\ForeignKeyConstraint; use Yiisoft\Db\Constraint\IndexConstraint; +use Yiisoft\Db\Driver\PDO\PdoAbstractSchema; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\ArrayHelper; -use Yiisoft\Db\Schema\AbstractSchema; use Yiisoft\Db\Schema\Builder\AbstractColumn; -use Yiisoft\Db\Schema\ColumnSchemaInterface; use Yiisoft\Db\Schema\Builder\ColumnInterface; +use Yiisoft\Db\Schema\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; use function array_map; @@ -92,7 +92,7 @@ * } * > */ -final class Schema extends AbstractSchema +final class Schema extends PdoAbstractSchema { /** * @var array Mapping from physical column types (keys) to abstract column types (values). @@ -413,7 +413,7 @@ protected function findViewNames(string $schema = ''): array */ protected function getCacheKey(string $name): array { - return array_merge([self::class], $this->db->getCacheKey(), [$this->getRawTableName($name)]); + return array_merge([self::class], $this->generateCacheKey(), [$this->getRawTableName($name)]); } /** @@ -425,7 +425,7 @@ protected function getCacheKey(string $name): array */ protected function getCacheTag(): string { - return md5(serialize(array_merge([self::class], $this->db->getCacheKey()))); + return md5(serialize(array_merge([self::class], $this->generateCacheKey()))); } /** diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index dd6c6071..a0494c65 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -9,6 +9,7 @@ use Yiisoft\Db\Command\CommandInterface; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Constraint\Constraint; +use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; @@ -406,7 +407,7 @@ public function testTableSchemaWithDbSchemes( $commandMock = $this->createMock(CommandInterface::class); $commandMock->method('queryAll')->willReturn([]); - $mockDb = $this->createMock(ConnectionInterface::class); + $mockDb = $this->createMock(ConnectionPDOInterface::class); $mockDb->method('getQuoter')->willReturn($db->getQuoter()); $mockDb ->method('createCommand') @@ -524,4 +525,15 @@ public function testTinyInt1() $this->assertEquals($status, $selectedRow['status']); $this->assertEquals(true, $selectedRow['bool_col']); } + + public function testNotConnectionPDO(): void + { + $db = $this->createMock(ConnectionInterface::class); + $schema = new Schema($db, DbHelper::getSchemaCache()); + + $this->expectException(NotSupportedException::class); + $this->expectExceptionMessage('Only PDO connections are supported.'); + + $schema->refreshTableSchema('customer'); + } }