packages/ztd-query-mysql/tests/Unit/Rewrite/Upsert/MetadataColumnsTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rewrite\Upsert;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use ZtdQuery\Platform\MySql\Rewrite\Upsert\MetadataColumns;
10
11#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\MySql\Sql\MySqlIdentifierQuoter::class)]
12#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\MySql\Sql\MySqlLexerProfile::class)]
13#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\MySql\Rewrite\Upsert\ExpressionBinder::class)]
14#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\MySql\Rewrite\Upsert\QualifiedColumn::class)]
15#[CoversClass(MetadataColumns::class)]
16final class MetadataColumnsTest extends TestCase
17{
18 public function testRender(): void
19 {
20 $quoter = new \ZtdQuery\Platform\MySql\Sql\MySqlIdentifierQuoter();
21 $binder = new \ZtdQuery\Platform\MySql\Rewrite\Upsert\ExpressionBinder($quoter, \ZtdQuery\Platform\MySql\Sql\MySqlLexerProfile::create());
22 $columns = new MetadataColumns($quoter, $binder);
23 $codec = new \ZtdQuery\Shadow\Mutation\UpsertMutationRow();
24 self::assertSame([
25 '(SELECT `__ztd_incoming`.`score` FROM `t` AS `__ztd_existing` WHERE TRUE LIMIT 1) AS `' . $codec->valueColumn(0) . '`',
26 '(SELECT `__ztd_existing`.`score` > 0 FROM `t` AS `__ztd_existing` WHERE TRUE LIMIT 1) AS `' . $codec->predicateColumn() . '`',
27 ], $columns->render('t', ['score'], ['score' => 'VALUES(score)'], 'TRUE', 'score > 0', null));
28 self::assertSame([], $columns->render('t', ['score'], [], 'TRUE', null, null));
29 }
30
31}
32