Skip to content

Commit

Permalink
Remove getCacheKey() to ConnectionInterface::class. (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Apr 5, 2023
1 parent 7aaed1d commit cd145f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Schema.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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)]);
}

/**
Expand All @@ -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())));
}

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/SchemaTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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');
}
}

0 comments on commit cd145f1

Please sign in to comment.