diff --git a/CHANGELOG.md b/CHANGELOG.md index e4801b87b..1448fd31f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik) - Enh #784: Remove unused code in `AbstractSchema::getTableIndexes()` (@vjik) - Bug #788: Fix casting integer to string in `AbstractCommand::getRawSql()` (@Tigrov) +- Enh #789: Remove unnecessary type casting to array in `AbstractDMLQueryBuilder::getTableUniqueColumnNames()` (@Tigrov) ## 1.2.0 November 12, 2023 diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index b3c0a4132..ba435dc10 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -380,7 +380,7 @@ static function (Constraint $constraint) use ($quoter, $columns, &$columnNames): $result = empty(array_diff($constraintColumnNames, $columns)); if ($result) { - $columnNames = array_merge((array) $columnNames, $constraintColumnNames); + $columnNames = array_merge($columnNames, $constraintColumnNames); } return $result; diff --git a/tests/AbstractQueryBuilderTest.php b/tests/AbstractQueryBuilderTest.php index d6de07f63..332c57186 100644 --- a/tests/AbstractQueryBuilderTest.php +++ b/tests/AbstractQueryBuilderTest.php @@ -210,14 +210,21 @@ public function testAlterColumn(): void * * @psalm-param array $columns */ - public function testBatchInsert(string $table, array $columns, iterable $rows, string $expected): void - { + public function testBatchInsert( + string $table, + array $columns, + iterable $rows, + string $expected, + array $expectedParams = [], + ): void { $db = $this->getConnection(); - $qb = $db->getQueryBuilder(); - $sql = $qb->batchInsert($table, $columns, $rows); + + $params = []; + $sql = $qb->batchInsert($table, $columns, $rows, $params); $this->assertSame($expected, $sql); + $this->assertSame($expectedParams, $params); } /** diff --git a/tests/Db/QueryBuilder/QueryBuilderTest.php b/tests/Db/QueryBuilder/QueryBuilderTest.php index 93356917f..c549aec3d 100644 --- a/tests/Db/QueryBuilder/QueryBuilderTest.php +++ b/tests/Db/QueryBuilder/QueryBuilderTest.php @@ -47,15 +47,22 @@ public function testAddDefaultValue(): void /** * @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::batchInsert */ - public function testBatchInsert(string $table, array $columns, iterable $rows, string $expected): void - { + public function testBatchInsert( + string $table, + array $columns, + iterable $rows, + string $expected, + array $expectedParams = [], + ): void { $db = $this->getConnection(); $schemaMock = $this->createMock(Schema::class); $qb = new QueryBuilder($db->getQuoter(), $schemaMock); + $params = []; try { - $this->assertSame($expected, $qb->batchInsert($table, $columns, $rows)); + $this->assertSame($expected, $qb->batchInsert($table, $columns, $rows, $params)); + $this->assertSame($expectedParams, $params); } catch (InvalidArgumentException|Exception) { } } diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index a70696668..3a960ab6a 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -145,7 +145,7 @@ public static function batchInsert(): array SQL, static::$driverName, ), - [':qp0' => 'test@example.com', ':qp1' => 'silverfire', ':qp2' => 'Kyiv {{city}}, Ukraine'], + 'expectedParams' => [':qp0' => 'test@example.com', ':qp1' => 'silverfire', ':qp2' => 'Kyiv {{city}}, Ukraine'], ], 'escape-danger-chars' => [ 'customer', @@ -157,7 +157,7 @@ public static function batchInsert(): array SQL, static::$driverName, ), - [':qp0' => "SQL-danger chars are escaped: '); --"], + 'expectedParams' => [':qp0' => "SQL-danger chars are escaped: '); --"], ], 'customer2' => [ 'customer', @@ -175,7 +175,7 @@ public static function batchInsert(): array SQL, static::$driverName, ), - [':qp0' => 'no columns passed'], + 'expectedParams' => [':qp0' => 'no columns passed'], ], 'bool-false, bool2-null' => [ 'type', @@ -187,7 +187,7 @@ public static function batchInsert(): array SQL, static::$driverName, ), - [':qp0' => 0, ':qp1' => null], + 'expectedParams' => [':qp0' => false, ':qp1' => null], ], 'wrong' => [ '{{%type}}', @@ -199,7 +199,7 @@ public static function batchInsert(): array SQL, static::$driverName, ), - [':qp0' => null, ':qp1' => null], + 'expectedParams' => [':qp0' => null, ':qp1' => null], ], 'bool-false, time-now()' => [ '{{%type}}', @@ -211,7 +211,7 @@ public static function batchInsert(): array SQL, static::$driverName, ), - [':qp0' => null], + 'expectedParams' => [':qp0' => false], ], 'column table names are not checked' => [ '{{%type}}', @@ -223,7 +223,7 @@ public static function batchInsert(): array SQL, static::$driverName, ), - [':qp0' => null, ':qp1' => null], + 'expectedParams' => [':qp0' => true, ':qp1' => false], ], 'empty-sql' => [ '{{%type}}',