packages/sql-semantics-mysql/tests/Unit/Rules/TableDefinition/ViewFactsTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\TableDefinition;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Construction\Derivation;
11use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
12use SqlSemantics\Platform\MySql\Platform;
13use SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewFacts;
14use SqlSemantics\Platform\MySql\Semantics;
15use SqlSemantics\Platform\MySql\Statement\View\CreateView;
16
17#[CoversClass(ViewFacts::class)]
18#[Medium]
19final class ViewFactsTest extends TestCase
20{
21    public function testDeriveAnswersTheDeclarationOfTheView(): void
22    {
23        $create = (new Semantics())->analyze('CREATE VIEW v AS SELECT 1 AS a');
24        $statement = $create->statement;
25        self::assertInstanceOf(CreateView::class, $statement);
26        $platform = new Platform();
27        $derivation = new Derivation($platform->context($platform->profile('mysql-8.4.7', null, ParameterStyle::Native), null, [], true));
28        $table = (new ViewFacts())->derive($statement->definition, $derivation);
29
30        self::assertSame('a', $table->columns[0]->name->value);
31    }
32}
33