From b047dae76935f55202b4bf79e96b1b6f70db584a Mon Sep 17 00:00:00 2001
From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com>
Date: Tue, 15 Aug 2023 07:33:13 -0400
Subject: [PATCH] Fix method `alterColumn()`, argument type accept
`ColumnInterface::class`. (#741)
---
.github/workflows/active-record.yml | 2 +-
.github/workflows/static.yml | 2 +-
CHANGELOG.md | 1 +
composer.json | 2 +-
phpunit.xml.dist | 38 +----------------------------
src/Command/AbstractCommand.php | 3 ++-
src/Command/CommandInterface.php | 9 ++++---
src/Debug/CommandInterfaceProxy.php | 3 ++-
8 files changed, 14 insertions(+), 46 deletions(-)
diff --git a/.github/workflows/active-record.yml b/.github/workflows/active-record.yml
index 9df63b13c..6f7b9cb78 100644
--- a/.github/workflows/active-record.yml
+++ b/.github/workflows/active-record.yml
@@ -26,7 +26,7 @@ jobs:
name: PHP ${{ matrix.php }}-active-record-${{ matrix.os }}
env:
- COMPOSER_ROOT_VERSION: 1.0.0
+ COMPOSER_ROOT_VERSION: 1.1.0
EXTENSIONS: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.10.1
runs-on: ${{ matrix.os }}
diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml
index fb7fc77dd..301ab7c15 100644
--- a/.github/workflows/static.yml
+++ b/.github/workflows/static.yml
@@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
- ['8.0', '8.1', '8.2']
+ ['8.1', '8.2']
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f412a938e..d15e625a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## 1.1.1 under development
+- Bug #741: Fix `alterColumn()` method to accept `ColumnInterface::class` in argument `$type` (@terabytesoftw)
- New #617: Add debug collector for `yiisoft/yii-debug` (@xepozz)
- Enh #617, #733: Add specific psalm annotation of `$closure` parameter in `ConnectionInterface::transaction()`
method (@xepozz, @vjik)
diff --git a/composer.json b/composer.json
index 1bb3b8b72..3c7ca79ea 100644
--- a/composer.json
+++ b/composer.json
@@ -34,7 +34,7 @@
"rector/rector": "^0.17",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
- "vimeo/psalm": "^4.30|^5.12.0",
+ "vimeo/psalm": "^4.30|^5.12",
"yiisoft/aliases": "^3.0",
"yiisoft/cache-file": "^2.0",
"yiisoft/di": "^1.0",
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index a95b8d3d0..39b4fff25 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -15,45 +15,9 @@
./src/TestSupport
+ ./src/Debug
./tests
./vendor
- ./src/Command/CommandInterface.php
- ./src/Command/ParamInterface.php
- ./src/Connection/ConnectionInterface.php
- ./src/Connection/ConnectionPoolInterface.php
- ./src/Constraint/ConstraintSchemaInterface.php
- ./src/Driver/DriverInterface.php
- ./src/Driver/PDO/CommandPDOInterface.php
- ./src/Driver/PDO/ConnectionPDOInterface.php
- ./src/Driver/PDO/ConnectionPDOPoolInterface.php
- ./src/Driver/PDO/PDODriverInterface.php
- ./src/Expression/ExpressionBuilderInterface.php
- ./src/Expression/ExpressionInterface.php
- ./src/Profiler/ProfilerInterface.php
- ./src/Query/BatchQueryResultInterface.php
- ./src/Query/Data/DataReaderInterface.php
- ./src/Query/QueryFunctionsInterface.php
- ./src/Query/QueryInterface.php
- ./src/Query/QueryPartsInterface.php
- ./src/QueryBuilder/Condition/Interface/BetweenColumnsConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/BetweenConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/ConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/ConjunctionConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/ExistConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/HashConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/InConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/LikeConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/NotConditionInterface.php
- ./src/QueryBuilder/Condition/Interface/SimpleConditionInterface.php
- ./src/QueryBuilder/DDLQueryBuilderInterface.php
- ./src/QueryBuilder/DMLQueryBuilderInterface.php
- ./src/QueryBuilder/DQLQueryBuilderInterface.php
- ./src/QueryBuilder/QueryBuilderInterface.php
- ./src/Schema/ColumnSchemaInterface.php
- ./src/Schema/QuoterInterface.php
- ./src/Schema/SchemaInterface.php
- ./src/Schema/TableSchemaInterface.php
- ./src/Transaction/TransactionInterface.php
diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php
index 2a04d05b3..479c1052e 100644
--- a/src/Command/AbstractCommand.php
+++ b/src/Command/AbstractCommand.php
@@ -11,6 +11,7 @@
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
+use Yiisoft\Db\Schema\Builder\ColumnInterface;
use function explode;
use function get_resource_type;
@@ -188,7 +189,7 @@ public function addUnique(string $table, string $name, array|string $columns): s
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
- public function alterColumn(string $table, string $column, string $type): static
+ public function alterColumn(string $table, string $column, ColumnInterface|string $type): static
{
$sql = $this->getQueryBuilder()->alterColumn($table, $column, $type);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php
index 55565f526..955e28c3b 100644
--- a/src/Command/CommandInterface.php
+++ b/src/Command/CommandInterface.php
@@ -14,6 +14,7 @@
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
+use Yiisoft\Db\Schema\Builder\ColumnInterface;
/**
* This interface represents a database command, such as a `SELECT`, `INSERT`, `UPDATE`, or `DELETE` statement.
@@ -138,13 +139,13 @@ public function addPrimaryKey(string $table, string $name, array|string $columns
*
* @param string $table The table whose column is to change.
* @param string $column The name of the column to change.
- * @param string $type The column type. {@see QueryBuilder::getColumnType()} will be called to convert the give
- * column type to the physical one. For example, `string` will be converted as `varchar(255)`, and `string not null`
- * becomes `varchar(255) not null`.
+ * @param ColumnInterface|string $type The column type. {@see QueryBuilder::getColumnType()} will be called to
+ * convert the give column type to the physical one. For example, `string` will be converted as `varchar(255)`, and
+ * `string not null` becomes `varchar(255) not null`.
*
* Note: The method will quote the `table` and `column` parameters before using them in the generated SQL.
*/
- public function alterColumn(string $table, string $column, string $type): static;
+ public function alterColumn(string $table, string $column, ColumnInterface|string $type): static;
/**
* Creates a batch INSERT command.
diff --git a/src/Debug/CommandInterfaceProxy.php b/src/Debug/CommandInterfaceProxy.php
index ebbccdd00..2ca7773c7 100644
--- a/src/Debug/CommandInterfaceProxy.php
+++ b/src/Debug/CommandInterfaceProxy.php
@@ -9,6 +9,7 @@
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
+use Yiisoft\Db\Schema\Builder\ColumnInterface;
final class CommandInterfaceProxy implements CommandInterface
{
@@ -92,7 +93,7 @@ public function addUnique(string $table, string $name, array|string $columns): s
/**
* @psalm-suppress MixedArgument
*/
- public function alterColumn(string $table, string $column, string $type): static
+ public function alterColumn(string $table, string $column, ColumnInterface|string $type): static
{
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
}