packages/sql-semantics-mysql/tests/Unit/Statement/Dml/Load/LoadInputTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Dml\Load;
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\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Dml\Load\LoadInput;
13use SqlSemantics\Platform\MySql\Statement\Dml\Load\LoadSource;
14use SqlSemantics\Platform\MySql\Statement\Literal\Numeral;
15use SqlSemantics\Platform\MySql\Statement\Literal\Text;
16
17#[CoversClass(LoadInput::class)]
18#[Medium]
19final class LoadInputTest extends TestCase
20{
21 public function testRenderWritesTheInput(): void
22 {
23 self::assertSame("LOAD DATA LOCAL INFILE 'f' `count` 2 IN PRIMARY KEY ORDER INTO TABLE t", (new Semantics('mysql-8.0.44'))->analyze("load data local infile 'f' count 2 in primary key order into table t")->toString());
24 self::assertSame("LOAD DATA INFILE 'f' `count` 2 INTO TABLE t", (new Semantics())->analyze("load data from infile 'f' count 2 into table t")->toString());
25 }
26
27 public function testRenderRejectsAnotherWord(): void
28 {
29 $this->expectExceptionMessage('The word before the number of files is COUNT.');
30
31 new LoadInput(false, LoadSource::Infile, new Text('f'), new Numeral('2'), false, new Name('many'));
32 }
33}
34