diff --git a/src/Column.php b/src/Column.php index d6869619..2a69f760 100644 --- a/src/Column.php +++ b/src/Column.php @@ -20,6 +20,10 @@ * * Provides a fluent interface, which means that the methods can be chained together to create a column schema with * many properties in a single line of code. + * + * @psalm-suppress DeprecatedClass + * + * @deprecated Use {@see StringColumnSchema} or other column classes instead. Will be removed in 2.0.0. */ final class Column extends AbstractColumn { diff --git a/src/DDLQueryBuilder.php b/src/DDLQueryBuilder.php index 15b8cd92..195812e7 100644 --- a/src/DDLQueryBuilder.php +++ b/src/DDLQueryBuilder.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder; use Yiisoft\Db\Schema\Builder\ColumnInterface; +use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use function count; @@ -81,7 +82,7 @@ public function addUnique(string $table, string $name, array|string $columns): s /** * @throws NotSupportedException SQLite doesn't support this method. */ - public function alterColumn(string $table, string $column, ColumnInterface|string $type): string + public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string { throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); } diff --git a/src/Schema.php b/src/Schema.php index 8526a0db..2fc9147f 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -78,6 +78,7 @@ final class Schema extends AbstractPdoSchema /** @deprecated Use {@see ColumnBuilder} instead. Will be removed in 2.0. */ public function createColumn(string $type, array|int|string $length = null): ColumnInterface { + /** @psalm-suppress DeprecatedClass */ return new Column($type, $length); } diff --git a/tests/ColumnSchemaBuilderTest.php b/tests/ColumnSchemaBuilderTest.php index 652a9fdd..70ed4147 100644 --- a/tests/ColumnSchemaBuilderTest.php +++ b/tests/ColumnSchemaBuilderTest.php @@ -23,12 +23,4 @@ public function testCustomTypes(string $expected, string $type, int|null $length { $this->checkBuildString($expected, $type, $length, $calls); } - - /** - * @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\ColumnSchemaBuilderProvider::createColumnTypes - */ - public function testCreateColumnTypes(string $expected, string $type, ?int $length, array $calls): void - { - parent::testCreateColumnTypes($expected, $type, $length, $calls); - } } diff --git a/tests/Provider/ColumnSchemaBuilderProvider.php b/tests/Provider/ColumnSchemaBuilderProvider.php index d92bf44c..3577e81c 100644 --- a/tests/Provider/ColumnSchemaBuilderProvider.php +++ b/tests/Provider/ColumnSchemaBuilderProvider.php @@ -22,23 +22,4 @@ public static function types(): array ['integer UNSIGNED', ColumnType::INTEGER, null, [['unsigned']]], ]; } - - public static function createColumnTypes(): array - { - $types = parent::createColumnTypes(); - - $types['uuid'][0] = '`column` blob(16)'; - $types['uuid not null'][0] = '`column` blob(16) NOT NULL'; - - $types['uuid with default'][0] = '`column` blob(16) DEFAULT (UNHEX(REPLACE(\'875343b3-6bd0-4bec-81bb-aa68bb52d945\',\'-\',\'\')))'; - $types['uuid with default'][3] = [['defaultExpression', '(UNHEX(REPLACE(\'875343b3-6bd0-4bec-81bb-aa68bb52d945\',\'-\',\'\')))']]; - - $types['uuid pk'][0] = '`column` blob(16) PRIMARY KEY'; - $types['uuid pk not null'][0] = '`column` blob(16) PRIMARY KEY NOT NULL'; - - $types['uuid pk not null with default'][0] = '`column` blob(16) PRIMARY KEY NOT NULL DEFAULT (RANDOMBLOB(16))'; - $types['uuid pk not null with default'][3] = [['notNull'],['defaultExpression', '(RANDOMBLOB(16))']]; - - return $types; - } } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index cbff92a7..b7d5ac97 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -6,7 +6,6 @@ use JsonException; use PHPUnit\Framework\Attributes\DataProviderExternal; -use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; @@ -18,7 +17,7 @@ use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; -use Yiisoft\Db\Sqlite\Column; +use Yiisoft\Db\Sqlite\Column\ColumnBuilder; use Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonQueryBuilderTest; @@ -32,6 +31,11 @@ final class QueryBuilderTest extends CommonQueryBuilderTest { use TestTrait; + public function getBuildColumnDefinitionProvider(): array + { + return QueryBuilderProvider::buildColumnDefinition(); + } + /** * @throws Exception * @throws InvalidConfigException @@ -162,20 +166,13 @@ public function testAddUnique(string $name, string $table, array|string $columns $qb->addUnique($table, $name, $columns); } - /** - * @throws Exception - * @throws InvalidConfigException - */ - public function testAlterColumn(): void + #[DataProviderExternal(QueryBuilderProvider::class, 'alterColumn')] + public function testAlterColumn(string|ColumnSchemaInterface $type, string $expected): void { - $db = $this->getConnection(); - - $qb = $db->getQueryBuilder(); - $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('Yiisoft\Db\Sqlite\DDLQueryBuilder::alterColumn is not supported by SQLite.'); - $qb->alterColumn('customer', 'email', ColumnType::STRING); + parent::testAlterColumn($type, $expected); } /** @@ -753,16 +750,16 @@ public function testUpsertExecute( public function testJsonColumn() { $qb = $this->getConnection()->getQueryBuilder(); - $columnSchemaBuilder = new Column(ColumnType::JSON); + $column = ColumnBuilder::json(); $this->assertSame( 'ALTER TABLE `json_table` ADD `json_col` json', - $qb->addColumn('json_table', 'json_col', $columnSchemaBuilder->asString()), + $qb->addColumn('json_table', 'json_col', $column), ); $this->assertSame( "CREATE TABLE `json_table` (\n\t`json_col` json\n)", - $qb->createTable('json_table', ['json_col' => $columnSchemaBuilder]), + $qb->createTable('json_table', ['json_col' => $column]), ); $this->assertSame(