diff --git a/CHANGELOG.md b/CHANGELOG.md index cb86d4e..140dfdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.0.1 under development +- Chg #88: Bump supported version of `yiisoft/db` to `^2.0` (@batyrmastyr) - Chg #91: Change supported PHP versions to `8.1 - 8.4` (@batyrmastyr) 1.0.0 May 09, 2023 diff --git a/composer.json b/composer.json index 89d3d70..295fb3d 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "ext-pdo": "*", "psr/log": "^2.0|^3.0", "psr/simple-cache": "^2.0|^3.0", - "yiisoft/db": "^1.0" + "yiisoft/db": "^2.0" }, "suggest": { "yiisoft/log": "^2.0" @@ -47,7 +47,8 @@ "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^5.22 || ^6.13.1", "yiisoft/cache": "^3.0", - "yiisoft/log": "^2.0" + "yiisoft/log": "^2.0", + "yiisoft/dummy-provider": "^1.0" }, "provide": { "psr/simple-cache-implementation": "1.0.0" diff --git a/psalm.xml b/psalm.xml index b48c894..2b2e0b2 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,6 +3,7 @@ errorLevel="1" findUnusedBaselineEntry="true" findUnusedCode="false" + ensureOverrideAttribute="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" diff --git a/src/DbCache.php b/src/DbCache.php index 0170b17..e6bf566 100644 --- a/src/DbCache.php +++ b/src/DbCache.php @@ -13,8 +13,8 @@ use Psr\SimpleCache\InvalidArgumentException; use Throwable; use Traversable; -use Yiisoft\Db\Command\Param; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Expression\Value\Param; use Yiisoft\Db\Query\Query; use function array_fill_keys; @@ -174,7 +174,7 @@ public function setMultiple(iterable $values, DateInterval|int|string|null $ttl if (!empty($rows) && !$this->isExpiredTtl($ttl)) { $this->db ->createCommand() - ->batchInsert($this->table, ['id', 'expire', 'data'], $rows) + ->insertBatch($this->table, $rows, ['id', 'expire', 'data']) ->execute(); } @@ -228,7 +228,7 @@ public function setLoggerMessageUpdate(string $value): void * Gets the cache data from the database. * * @param array|string $id One or more IDs for deleting data. - * @param array $fields Selectable fields. + * @param string[] $fields Selectable fields. * @param string $method Method of the returned data ("all", "scalar", "exists"). * * @return mixed The cache data. diff --git a/src/DbSchemaManager.php b/src/DbSchemaManager.php index 66713b9..72373fe 100644 --- a/src/DbSchemaManager.php +++ b/src/DbSchemaManager.php @@ -9,7 +9,6 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Schema\SchemaInterface; /** * Manages the cache table schema in the database. @@ -32,19 +31,17 @@ public function __construct(private ConnectionInterface $db) */ public function ensureTable(string $table = '{{%yii_cache}}'): void { - $schema = $this->db->getSchema(); - $tableRawName = $schema->getRawTableName($table); - - if ($this->hasTable($table)) { + $tableRawName = $this->db->getQuoter()->getRawTableName($table); + if ($this->hasTable($tableRawName)) { return; } $this->db->createCommand()->createTable( $table, [ - 'id' => $schema->createColumn(SchemaInterface::TYPE_STRING, 128)->notNull(), - 'data' => $schema->createColumn(SchemaInterface::TYPE_BINARY), - 'expire' => $schema->createColumn(SchemaInterface::TYPE_INTEGER), + 'id' => $this->db->getColumnBuilderClass()::string(128)->notNull(), + 'data' => $this->db->getColumnBuilderClass()::binary(), + 'expire' => $this->db->getColumnBuilderClass()::integer(), "CONSTRAINT [[PK_$tableRawName]] PRIMARY KEY ([[id]])", ], )->execute(); @@ -61,10 +58,9 @@ public function ensureTable(string $table = '{{%yii_cache}}'): void */ public function ensureNoTable(string $table = '{{%yii_cache}}'): void { - $tableRawName = $this->db->getSchema()->getRawTableName($table); - - if ($this->hasTable($table)) { - $this->db->createCommand()->dropTable($tableRawName)->execute(); + $rawTableName = $this->db->getQuoter()->getRawTableName($table); + if ($this->hasTable($rawTableName)) { + $this->db->createCommand()->dropTable($rawTableName)->execute(); } } @@ -77,6 +73,6 @@ public function ensureNoTable(string $table = '{{%yii_cache}}'): void */ private function hasTable(string $table): bool { - return $this->db->getTableSchema($table, true) !== null; + return $this->db->getSchema()->hasTable($table, refresh: true); } } diff --git a/tests/Common/AbstractDbSchemaManagerTest.php b/tests/Common/AbstractDbSchemaManagerTest.php index ef1fd56..ee4cf74 100644 --- a/tests/Common/AbstractDbSchemaManagerTest.php +++ b/tests/Common/AbstractDbSchemaManagerTest.php @@ -9,11 +9,10 @@ use Yiisoft\Cache\Db\DbCache; use Yiisoft\Cache\Db\DbSchemaManager; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Constraint\IndexConstraint; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Schema\SchemaInterface; /** * @group Mssql @@ -70,6 +69,8 @@ public function testEnsureTableAndDropTable(string $table): void */ public function testEnsureTableExist(string $table): void { + $this->assertNull($this->db->getTableSchema($table, true)); + $this->dbSchemaManager->ensureTable($table); $this->assertNotNull($this->db->getTableSchema($table, true)); @@ -99,12 +100,12 @@ public function testVerifyTableIndexes(string $table): void $schema = $this->db->getSchema(); - /** @psalm-var IndexConstraint[] $indexes */ - $indexes = $schema->getTableIndexes($dbCache->getTable(), true); + $index = $schema->getTablePrimaryKey($dbCache->getTable(), true); - $this->assertSame(['id'], $indexes[0]->getColumnNames()); - $this->assertTrue($indexes[0]->isUnique()); - $this->assertTrue($indexes[0]->isPrimary()); + $this->assertNotNull($index); + $this->assertSame(['id'], $index->columnNames); + $this->assertTrue($index->isUnique); + $this->assertTrue($index->isPrimaryKey); $this->dbSchemaManager->ensureNoTable($dbCache->getTable()); @@ -126,17 +127,17 @@ public function testVerifyTableStructure(string $table): void $this->dbSchemaManager->ensureTable($dbCache->getTable()); $tableSchema = $this->db->getTableSchema($dbCache->getTable()); - $tableRawName = $this->db->getSchema()->getRawTableName($dbCache->getTable()); + $tableRawName = $this->db->getQuoter()->getRawTableName($dbCache->getTable()); $this->assertNotNull($tableSchema); $this->assertSame($tableRawName, $tableSchema->getName()); $this->assertSame(['id'], $tableSchema->getPrimaryKey()); $this->assertSame(['id', 'data', 'expire'], $tableSchema->getColumnNames()); - $this->assertSame(SchemaInterface::TYPE_STRING, $tableSchema->getColumn('id')?->getType()); + $this->assertSame(ColumnType::STRING, $tableSchema->getColumn('id')?->getType()); $this->assertSame(128, $tableSchema->getColumn('id')?->getSize()); - $this->assertSame(SchemaInterface::TYPE_BINARY, $tableSchema->getColumn('data')?->getType()); - $this->assertSame(SchemaInterface::TYPE_INTEGER, $tableSchema->getColumn('expire')?->getType()); + $this->assertSame(ColumnType::BINARY, $tableSchema->getColumn('data')?->getType()); + $this->assertSame(ColumnType::INTEGER, $tableSchema->getColumn('expire')?->getType()); $this->dbSchemaManager->ensureNoTable($dbCache->getTable()); diff --git a/tests/Common/AbstractSQLDumpFileTest.php b/tests/Common/AbstractSQLDumpFileTest.php index 5aa4f8b..34c2b78 100644 --- a/tests/Common/AbstractSQLDumpFileTest.php +++ b/tests/Common/AbstractSQLDumpFileTest.php @@ -8,11 +8,10 @@ use Throwable; use Yiisoft\Cache\Db\DbCache; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Constraint\IndexConstraint; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Schema\SchemaInterface; /** * @group Mssql @@ -71,12 +70,12 @@ public function testVerifyTableIndexes(): void $schema = $this->db->getSchema(); - /** @psalm-var IndexConstraint[] $indexes */ - $indexes = $schema->getTableIndexes($dbCache->getTable(), true); + $index = $schema->getTablePrimaryKey($dbCache->getTable(), true); - $this->assertSame(['id'], $indexes[0]->getColumnNames()); - $this->assertTrue($indexes[0]->isUnique()); - $this->assertTrue($indexes[0]->isPrimary()); + $this->assertNotNull($index); + $this->assertSame(['id'], $index->columnNames); + $this->assertTrue($index->isPrimaryKey); + $this->assertTrue($index->isUnique); $this->loadFromSQLDumpFile(dirname(__DIR__, 2) . "/sql/$this->driverName-down.sql"); @@ -96,17 +95,17 @@ public function testVerifyTableStructure(): void $this->loadFromSQLDumpFile(dirname(__DIR__, 2) . "/sql/$this->driverName-up.sql"); $tableSchema = $this->db->getTableSchema($dbCache->getTable()); - $tableRawName = $this->db->getSchema()->getRawTableName($dbCache->getTable()); + $tableRawName = $this->db->getQuoter()->getRawTableName($dbCache->getTable()); $this->assertNotNull($tableSchema); $this->assertSame($tableRawName, $tableSchema->getName()); $this->assertSame(['id'], $tableSchema->getPrimaryKey()); $this->assertSame(['id', 'data', 'expire'], $tableSchema->getColumnNames()); - $this->assertSame(SchemaInterface::TYPE_STRING, $tableSchema->getColumn('id')?->getType()); + $this->assertSame(ColumnType::STRING, $tableSchema->getColumn('id')?->getType()); $this->assertSame(128, $tableSchema->getColumn('id')?->getSize()); - $this->assertSame(SchemaInterface::TYPE_BINARY, $tableSchema->getColumn('data')?->getType()); - $this->assertSame(SchemaInterface::TYPE_INTEGER, $tableSchema->getColumn('expire')?->getType()); + $this->assertSame(ColumnType::BINARY, $tableSchema->getColumn('data')?->getType()); + $this->assertSame(ColumnType::INTEGER, $tableSchema->getColumn('expire')?->getType()); $this->loadFromSQLDumpFile(dirname(__DIR__, 2) . "/sql/$this->driverName-down.sql"); diff --git a/tests/Support/MssqlFactory.php b/tests/Support/MssqlFactory.php index 59ee6e7..edacf78 100644 --- a/tests/Support/MssqlFactory.php +++ b/tests/Support/MssqlFactory.php @@ -14,7 +14,7 @@ final class MssqlFactory extends ConnectionFactory public function createConnection(): ConnectionInterface { $pdoDriver = new Driver( - (new Dsn('sqlsrv', 'localhost', 'yiitest;TrustServerCertificate=1'))->asString(), + new Dsn('sqlsrv', 'localhost', 'yiitest;TrustServerCertificate=1'), 'SA', 'YourStrong!Passw0rd', ); diff --git a/tests/Support/MysqlFactory.php b/tests/Support/MysqlFactory.php index e5e45d8..a3395bd 100644 --- a/tests/Support/MysqlFactory.php +++ b/tests/Support/MysqlFactory.php @@ -14,7 +14,7 @@ final class MysqlFactory extends ConnectionFactory public function createConnection(): ConnectionInterface { $pdoDriver = new Driver( - (new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString(), + new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']), 'root', '', ); diff --git a/tests/Support/OracleFactory.php b/tests/Support/OracleFactory.php index 9546f7f..884b19c 100644 --- a/tests/Support/OracleFactory.php +++ b/tests/Support/OracleFactory.php @@ -15,7 +15,7 @@ final class OracleFactory extends ConnectionFactory public function createConnection(): ConnectionInterface { $pdoDriver = new Driver( - (new Dsn('oci', 'localhost', 'XE', '1521', ['charset' => 'AL32UTF8']))->asString(), + new Dsn('oci', 'localhost', 'XE', '1521', ['charset' => 'AL32UTF8']), 'system', 'root' ); diff --git a/tests/Support/PgsqlFactory.php b/tests/Support/PgsqlFactory.php index 2f15395..6dfebe5 100644 --- a/tests/Support/PgsqlFactory.php +++ b/tests/Support/PgsqlFactory.php @@ -14,7 +14,7 @@ final class PgsqlFactory extends ConnectionFactory public function createConnection(): ConnectionInterface { $pdoDriver = new Driver( - (new Dsn('pgsql', '127.0.0.1', 'yiitest', '5432'))->asString(), + new Dsn('pgsql', '127.0.0.1', 'yiitest', '5432'), 'root', 'root', ); diff --git a/tests/Support/SqliteFactory.php b/tests/Support/SqliteFactory.php index 589e625..1e8d314 100644 --- a/tests/Support/SqliteFactory.php +++ b/tests/Support/SqliteFactory.php @@ -13,7 +13,7 @@ final class SqliteFactory extends ConnectionFactory { public function createConnection(): ConnectionInterface { - $pdoDriver = new Driver((new Dsn('sqlite', __DIR__ . '/runtime/yiitest.sq3'))->asString()); + $pdoDriver = new Driver(new Dsn('sqlite', __DIR__ . '/runtime/yiitest.sq3')); return new Connection($pdoDriver, $this->createSchemaCache()); }