diff --git a/CHANGELOG.md b/CHANGELOG.md index 0912aba1b..9e5d91170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ ## 1.0.1 under development -- no changes in this release. +- Chg #722: Remove legacy array syntax for typecast. Use `Param` instead (@terabytesoftw) ## 1.0.0 April 12, 2023 -- Initial release. \ No newline at end of file +- Initial release. diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fa0bb4859..a95b8d3d0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,76 +1,85 @@ - - - - ./src - - - ./src/TestSupport - ./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 - - - - - - - - ./tests/Db - - - ./vendor/yiisoft/active-record/tests/Driver - - - ./vendor/yiisoft/db-mssql/tests - - - ./vendor/yiisoft/db-mysql/tests - - - ./vendor/yiisoft/db-oracle/tests - - - ./vendor/yiisoft/db-pgsql/tests - - - ./vendor/yiisoft/db-sqlite/tests - - + + + + ./src + + + ./src/TestSupport + ./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 + + + + + + + + ./tests/Db + + + ./vendor/yiisoft/active-record/tests/Driver + + + ./vendor/yiisoft/db-mssql/tests + + + ./vendor/yiisoft/db-mysql/tests + + + ./vendor/yiisoft/db-oracle/tests + + + ./vendor/yiisoft/db-pgsql/tests + + + ./vendor/yiisoft/db-sqlite/tests + + diff --git a/src/Connection/AbstractConnection.php b/src/Connection/AbstractConnection.php index e5d445b18..0f53bee6e 100644 --- a/src/Connection/AbstractConnection.php +++ b/src/Connection/AbstractConnection.php @@ -5,7 +5,6 @@ namespace Yiisoft\Db\Connection; use Closure; -use Exception; use Throwable; use Yiisoft\Db\Query\BatchQueryResult; use Yiisoft\Db\Query\BatchQueryResultInterface; diff --git a/src/Schema/AbstractColumnSchema.php b/src/Schema/AbstractColumnSchema.php index 10d662aac..41499a432 100644 --- a/src/Schema/AbstractColumnSchema.php +++ b/src/Schema/AbstractColumnSchema.php @@ -4,15 +4,11 @@ namespace Yiisoft\Db\Schema; -use Yiisoft\Db\Command\DataType; -use Yiisoft\Db\Command\Param; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Helper\DbStringHelper; -use function count; use function gettype; use function in_array; -use function is_array; use function is_bool; use function is_float; use function is_resource; @@ -271,15 +267,6 @@ protected function typecast(mixed $value): mixed return $value; } - if ( - is_array($value) - && count($value) === 2 - && isset($value[1]) - && in_array($value[1], $this->getDataTypes(), true) - ) { - return new Param((string) $value[0], $value[1]); - } - switch ($this->phpType) { case SchemaInterface::PHP_TYPE_RESOURCE: case SchemaInterface::PHP_TYPE_STRING: @@ -312,19 +299,4 @@ protected function typecast(mixed $value): mixed return $value; } - - /** - * @return int[] Array of numbers that represent possible parameter types. - */ - private function getDataTypes(): array - { - return [ - DataType::BOOLEAN, - DataType::INTEGER, - DataType::STRING, - DataType::LOB, - DataType::NULL, - DataType::STMT, - ]; - } } diff --git a/tests/Common/CommonSchemaTest.php b/tests/Common/CommonSchemaTest.php index b0250564c..c91b4e9ff 100644 --- a/tests/Common/CommonSchemaTest.php +++ b/tests/Common/CommonSchemaTest.php @@ -33,6 +33,7 @@ use function ksort; use function mb_chr; use function sort; +use function str_replace; use function strtolower; abstract class CommonSchemaTest extends AbstractSchemaTest @@ -1148,6 +1149,29 @@ public function testWorkWithIndex( $db->close(); } + /** + * @link https://github.com/yiisoft/db/issues/718 + */ + public function testIssue718(): void + { + $db = $this->getConnection(); + + if ($db->getDriverName() === 'oci' || $db->getDriverName() === 'sqlite' || $db->getDriverName() === 'sqlsrv') { + $this->markTestSkipped('Test is not supported by sqlite, oci and sqlsrv drivers.'); + } + + if ($db->getTableSchema('{{%table}}', true) !== null) { + $db->createCommand()->dropTable('{{%table}}')->execute(); + } + + $db->createCommand()->createTable('{{%table}}', ['array' => 'json'])->execute(); + $db->createCommand()->insert('{{%table}}', ['array' => [1, 2]])->execute(); + + $result = str_replace(' ', '', $db->createCommand('SELECT * FROM {{%table}}')->queryScalar()); + + $this->assertSame('[1,2]', trim($result)); + } + protected function createTableForIndexAndConstraintTests( ConnectionInterface $db, string $tableName, diff --git a/tests/Db/Schema/ColumnSchemaTest.php b/tests/Db/Schema/ColumnSchemaTest.php index c6c414b10..b2b1a2838 100644 --- a/tests/Db/Schema/ColumnSchemaTest.php +++ b/tests/Db/Schema/ColumnSchemaTest.php @@ -5,8 +5,6 @@ namespace Yiisoft\Db\Tests\Db\Schema; use PHPUnit\Framework\TestCase; -use Yiisoft\Db\Command\DataType; -use Yiisoft\Db\Command\ParamInterface; use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\Stub\ColumnSchema; @@ -144,6 +142,18 @@ public function testExtra(): void $this->assertSame('', $column->getExtra()); } + /** + * @link https://github.com/yiisoft/db/issues/718 + */ + public function testTypecastIssue718(): void + { + $column = new ColumnSchema('new'); + + $param = [1, 2]; + $result = $column->dbTypecast($param); + $this->assertSame([1, 2], $result); + } + public function testName(): void { $column = new ColumnSchema('test'); @@ -238,17 +248,6 @@ public function testPhpTypecastWithStringNullValue(): void $this->assertNull($column->phpTypecast(null)); } - public function testPhpTypecastWithStringParamValue(): void - { - $column = new ColumnSchema('new'); - - $column->phpType(SchemaInterface::PHP_TYPE_STRING); - - $this->assertInstanceOf(ParamInterface::class, $column->phpTypecast(['test', DataType::STRING])); - $this->assertSame('test', $column->phpTypecast(['test', DataType::STRING])->getValue()); - $this->assertSame(DataType::STRING, $column->phpTypecast(['test', DataType::STRING])->getType()); - } - public function testPhpTypecastWithStringResourceValue(): void { $column = new ColumnSchema('new');