Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 12 additions & 0 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}