packages/sql-semantics-mysql/tests/Unit/Rules/Dml/LoadFactsTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Dml;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Declaration\Column;
11use SqlSemantics\Platform\MySql\Model\Statement\Declaration\Table;
12use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
13use SqlSemantics\Platform\MySql\Model\Statement\Identifier\QualifiedName;
14use SqlSemantics\Platform\MySql\Model\Statement\Reference\Column\MissingColumn;
15use SqlSemantics\Platform\MySql\Model\Statement\Type\Nullability;
16use SqlSemantics\Platform\MySql\Rules\Dml\LoadFacts;
17use SqlSemantics\Platform\MySql\Semantics;
18use SqlSemantics\Platform\MySql\Statement\Type\Integral;
19use SqlSemantics\Platform\MySql\Statement\Type\Kind\IntegralKind;
20
21#[CoversClass(LoadFacts::class)]
22#[Medium]
23final class LoadFactsTest extends TestCase
24{
25    public function testDeriveReportsAnUnknownColumn(): void
26    {
27        $semantics = new Semantics();
28        $t = new Table(new QualifiedName(new Name('t'), new Name('(current)')), $semantics->profile(), [new Column(new Name('a'), new Integral(IntegralKind::Int), Nullability::NotNull), new Column(new Name('b'), new Integral(IntegralKind::BigInt))]);
29        $operation = $semantics->inspect("LOAD DATA INFILE 'f' INTO TABLE t (a, z)", [$t]);
30
31        self::assertInstanceOf(MissingColumn::class, $operation->facts->diagnostics[0]);
32    }
33}
34