From 0dc7b46f89f35cef14745bd74ea3d171796aece9 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 20 Jun 2025 17:13:49 +0700 Subject: [PATCH] Adapt test for changes in `db` --- tests/Provider/QueryBuilderProvider.php | 22 ++++++++++++++++++++++ tests/QueryBuilderTest.php | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index fbb585c8..0ddf1629 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -389,4 +389,26 @@ public static function multiOperandFunctionBuilder(): array return $data; } + + public static function upsertWithMultiOperandFunctions(): array + { + $data = parent::upsertWithMultiOperandFunctions(); + + unset( + $data[0][2]['array_col'], + $data[0][4]['array_col'], + ); + + $data[0][3] = 'INSERT INTO `test_upsert_with_functions`' + . ' (`id`, `array_col`, `greatest_col`, `least_col`, `longest_col`, `shortest_col`)' + . ' SELECT `id`, `array_col`, `greatest_col`, `least_col`, `longest_col`, `shortest_col`' + . ' FROM (SELECT 1 AS `id`, :qp0 AS `array_col`, 5 AS `greatest_col`, 5 AS `least_col`, :qp1 AS `longest_col`, :qp2 AS `shortest_col`)' + . ' AS EXCLUDED ON DUPLICATE KEY UPDATE' + . ' `greatest_col`=GREATEST(`test_upsert_with_functions`.`greatest_col`, EXCLUDED.`greatest_col`),' + . ' `least_col`=LEAST(`test_upsert_with_functions`.`least_col`, EXCLUDED.`least_col`),' + . ' `longest_col`=(SELECT `test_upsert_with_functions`.`longest_col` AS value UNION SELECT EXCLUDED.`longest_col` AS value ORDER BY LENGTH(value) DESC LIMIT 1),' + . ' `shortest_col`=(SELECT `test_upsert_with_functions`.`shortest_col` AS value UNION SELECT EXCLUDED.`shortest_col` AS value ORDER BY LENGTH(value) ASC LIMIT 1)'; + + return $data; + } } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index b2c488ec..28f45156 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -859,4 +859,16 @@ public function testMultiOperandFunctionBuilderWithType( $this->assertEquals($expectedResult, $result); } + + #[DataProviderExternal(QueryBuilderProvider::class, 'upsertWithMultiOperandFunctions')] + public function testUpsertWithMultiOperandFunctions( + array $initValues, + array|QueryInterface $insertValues, + array $updateValues, + string $expectedSql, + array $expectedResult, + array $expectedParams = [], + ): void { + parent::testUpsertWithMultiOperandFunctions($initValues, $insertValues, $updateValues, $expectedSql, $expectedResult, $expectedParams); + } }