packages/sql-semantics-mysql/tests/Unit/Statement/Dml/Insert/InsertIntoTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Dml\Insert;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\MySql\Model\Statement\Identifier\QualifiedName;
12use SqlSemantics\Platform\MySql\Semantics;
13use SqlSemantics\Platform\MySql\Statement\Dml\Insert\InsertInto;
14use SqlSemantics\Platform\MySql\Statement\Dml\WriteTarget;
15
16#[CoversClass(InsertInto::class)]
17#[Medium]
18final class InsertIntoTest extends TestCase
19{
20    public function testRenderWritesVerbModifiersAndTable(): void
21    {
22        self::assertSame('INSERT HIGH_PRIORITY IGNORE INTO t PARTITION (p) (a) VALUES (1)', (new Semantics())->analyze('insert high_priority ignore t partition (p) (a) values (1)')->toString());
23        self::assertSame('REPLACE DELAYED INTO t VALUES (1)', (new Semantics('mysql-5.6.51'))->analyze('replace delayed t value (1)')->toString());
24    }
25
26    public function testRenderRejectsReplaceWithIgnore(): void
27    {
28        $this->expectExceptionMessage('REPLACE takes neither IGNORE nor HIGH_PRIORITY.');
29
30        new InsertInto(true, null, true, new WriteTarget(new QualifiedName(new Name('t'))));
31    }
32
33    public function testRenderRejectsACorrelationName(): void
34    {
35        $this->expectExceptionMessage('The table of INSERT and REPLACE has no correlation name.');
36
37        new InsertInto(false, null, false, new WriteTarget(new QualifiedName(new Name('t')), new Name('x')));
38    }
39}
40